[英]Align button top to textview end
This might be a silly silly question, nonetheless, has successfully driven me crazy. 但是,这可能是一个愚蠢的愚蠢问题,已经使我疯狂。
How would one go about getting this kind of an alignment? 人们将如何进行这种调整?
What layout would I use? 我将使用哪种布局? How would I set the widths of these elements as some sort of a percentage?
如何将这些元素的宽度设置为某种百分比?
Use this: 用这个:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="bsdvdsjvbdsjfvcbdsvjdsbvbcvm vm,cxvmjbvjcbvjxvbxncvcxvxcbzbdfgdfzzgdfgdfgdfzgdfzvgzxvbnxcjkdsbvckjdsvbchsvgdhjsdvbndsbchjsdfgdshfgdshcb nsxbc" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="bottom"
android:text="CheckBox" />
</LinearLayout>
Try this.. 尝试这个..
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="top"
android:gravity="top"
android:text="yourtext" />
<ImageView
android:id="@+id/img_icon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="bottom"
android:src="@drawable/yourimageview" />
</LinearLayout>
Place your textview and checkbox in a horizontal alignment in your html. 将您的textview和复选框在html中水平对齐。 Set the android:gravity='bottom' attribute for the checkbox.
设置复选框的android:gravity ='bottom'属性。 To set the widths, use the android:gravity attribute.
要设置宽度,请使用android:gravity属性。 The numbers you use for gravity don't really matter;
您用于重力的数字并不重要; the size will be set based on the total of the gravities within the view you are using.
大小将根据您正在使用的视图内的重力总数进行设置。 Ff the text is gravity 5 and the checkbox is gravity 1, the text will fill 84% of the view and the cb to 16%.
如果文本是重力5,复选框是重力1,则文本将填充视图的84%,而cb将填充到视图的16%。 the same would happen using 50 and 10. The total is 100%.
使用50和10也会发生相同的情况。总数为100%。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.