【发布时间】:2015-08-21 01:14:43
【问题描述】:
无法进行简单的 RelativeLayout。我正在构建一个由如下所示的行组成的 ListView:
+-----------------------------+--------------+
| Line 1 | Small button |
| Line 2, more text | |
| Line 3, even more text | |
这是我的第一次尝试 - 不幸的是,垂直分隔线没有出现。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="@+id/lineOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textColor="@color/wallet_holo_blue_light"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+id/lineTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/lineOne"
android:textSize="16dp" />
<TextView
android:id="@+id/lineThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/lineTwo"
android:textSize="14dp" />
<ImageButton
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"
android:focusable="false"
android:focusableInTouchMode="false"
android:onClick="doSomething"
android:src="@drawable/arrow_down" />
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_toLeftOf="@id/myButton"
android:background="?android:attr/listDivider" />
</RelativeLayout>
编辑:我几乎用下面的代码解决了我自己的问题。
现在我的布局看起来不错...
+-----------------------------+--------------+
| Line 1 | Small button |
| Line 2, more text | |
| Line 3, even more text | |
... 除非例如第一行太长 - 在这种情况下,分隔符和按钮不会显示:
+-----------------------------+--------------+
| Line 1, way way way way too long which |
| wraps |
| Line 2, more text |
| Line 3, even more text |
您能帮我做最后的调整吗?
非常感谢!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/lineOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/wallet_holo_blue_light"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+id/lineTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp" />
<TextView
android:id="@+id/lineThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp" />
</LinearLayout>
<!-- As per http://stackoverflow.com/questions/6992804/how-to-right-align-widget-in-horizontal-linear-layout-android -->
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal">
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="?android:attr/listDivider" />
<ImageButton
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="@drawable/arrow_down" />
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
我查看了您的文件,应该没问题。我只查看了预览,但在我的情况下显示了垂直分隔线。您在预览中没有看到任何分隔线?还是也只是预览版?
-
您还应该考虑将
layout_height设置为wrap_content,因为它们是列表视图项。 -
感谢您对此进行调查!我确实在预览中看到了分隔线,但在我的手机上没有。
标签: android