我创建了一个自定义列表视图。尽管我对列表项的布局感到吃力,但一切都很好。
这个想法是要有一个文本视图,它可以具有可变的长度(可以有多行),并且在文本视图旁边的两个按钮全部在一行上。
这就是我所拥有的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_weight=".80" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
android:layout_weight=".10"
android:layout_toRightOf="@id/textView1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"
android:layout_weight=".10"
android:layout_toRightOf="@id/button1" />
尽管我的问题是文本视图填充了父级并按下了屏幕上的按钮,但这仍然可以正常工作。(当我有一个简短的文本时,按钮是可见的)
所以基本上,我需要的是向左对齐80%宽的textview和向右对齐两个10%宽的按钮。谁能指导我正确的方向?
谢谢
您不能layout_weight
与一起使用RelativeLayout
。试试这个:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_weight="1" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B" />
</LinearLayout>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句