【发布时间】:2014-10-30 06:12:48
【问题描述】:
我有一个列表视图,其中每个列表视图项看起来像这样!
ListViewItem 是一个RelativeLayout。现在我在创建两个分屏按钮时遇到问题。目前我正在这样做。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_below="@+id/ReviewText">
<RelativeLayout
android:layout_weight="1"
android:layout_height="fill_parent" android:layout_width="0dp"
android:onClick="likeClicked"
android:clickable="true" >
<!-- SOME CODE -->
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_height="fill_parent" android:layout_width="0dp"
android:onClick="likeClicked"
android:clickable="true" >
<!-- SOME CODE -->
</RelativeLayout>
</LinearLayout>
<RelativeLayout>
这工作得很好,但android dev documentation here 说
此外,嵌套了几个使用 layout_weight 参数可能特别昂贵,因为每个孩子 需要测量两次。这一点尤其重要,当 布局反复膨胀,例如在 ListView 中使用时或 网格视图。
我可以改进我的代码以提高性能吗?如果是,如何?有没有其他方法可以在不使用 LinearLayout 的情况下均匀拆分两个按钮?
【问题讨论】:
-
LinearLayout'sweight 是理想的,但如果你想用 RelativeLayout 来做,你需要以编程方式设置布局的百分比参数。检查这个例如代码stackoverflow.com/a/16519595/1939564
标签: android android-layout listview android-listview