【发布时间】:2014-02-03 22:10:27
【问题描述】:
我已经阅读了我能找到的所有内容,但我无法弄清楚这一点。我有一个带有标题的 XML,然后是一个列表视图,最后一行有 2 个按钮。为了使布局看起来完美,我已经“硬编码”了列表视图的大小(467dp)。这在我的三星 Galaxy S4 上很好,但我不确定它在其他尺寸略有不同的手机上是否合适。我在 Galaxy 8" 选项卡上对其进行了测试,但它看起来不正确。然后我在 10.1" 选项卡上对其进行了测试,它(再次)看起来不正确。基本上底部按钮在屏幕中间。我通过为 sw600dp 和 sw720dp 创建布局来解决这个问题。对于其中的每一个,我必须为列表视图硬编码不同的大小。在我看来,有一种更好的方法可以让标题列表视图按钮 XML 在任何设备上显示(相对)相同。谁能告诉我如何更改我的 XML,这样我就不必对列表视图的大小进行硬编码?
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/title_line"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="@string/workout_locations">
</TextView>
<ListView
android:id="@+id/location_list"
android:layout_width="match_parent"
android:layout_height="467dp"
android:longClickable="true" >
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/help_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/help_description"
/>
<ImageButton
android:id="@+id/add_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/add_description"
/>
</LinearLayout>
</LinearLayout>
【问题讨论】:
标签: android xml listview android-listview