我需要为列表视图项目创建一个布局,如下所示。但我试图不去创造它,但我也在考虑表现。我尝试过使用带有weight属性的嵌套线性布局来做到这一点,但据我所知,使用具有这种属性的嵌套线性布局并不是一个好习惯,因为它会降低我的应用程序的性能。此外,我试图使用相对布局,但我没有达到预期的结果。中间文本视图应该提供最多的空间。 在此先感谢您的帮助。创建列表项目的最佳做法
0
A
回答
0
也许我没有理解错的话,也许-or有一定的要求,你没有说,但我认为它应该满足您的需求:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal"
android:weightSum="1">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:background="#8E7AE5"></RelativeLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#E57A7A"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#D5E57A"
android:gravity="center"
android:text="Top" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="Down" />
</LinearLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:background="#8E7AE5"></RelativeLayout>
</LinearLayout>
0
嗯,我会做这样的:
<LinearLayout xmlns:andoird="http://schemas.android.com/apk/res/android"
andoird:layout_width="match_parent"
andoird:layout_height="48dp"
andoird:orientation="horizontal"
android:weightSum:1>
<TextView
andoird:layout_width="0dp"
andoird:layout_height="match_parent"
andoird:layout_weight="0.25"
andoird:text="Left textView"/>
<!-- Middle container -->
<LinearLayout
andoird:layout_width="0dp"
andoird:layout_height="wrap_content"
andoird:layout_weight="0.5"
andoird:orientation="vertical">
<TextView
andoird:layout_width="match_parent"
andoird:layout_height="24dp"
andoird:text="Middle Top textView"/>
<TextView
andoird:layout_width="match_parent"
andoird:layout_height="24dp"
andoird:text="Middle Bottom textView"/>
</LinearLayout>
<Switch
andoird:layout_width="0dp"
andoird:layout_height="match_parent"
andoird:layout_weight="0.25"
andoird:text="Right switch" />
ŧ他的布局不会抛出关于性能的任何XML警告。说到性能,你应该在你的ListView适配器中使用你的ViewHolder。它有助于很多。
0
试试这个方法,希望这会帮助你解决你的问题。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center_vertical"
android:paddingLeft="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textview"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.50"
android:orientation="vertical"
android:paddingLeft="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textview"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textview"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center_vertical"
android:paddingLeft="10dp">
<Switch
android:id="@+id/main_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
注:我想使用的LinearLayout体重就可以达到您的要求。
相关问题
- 1. 从列表框中查找大量项目的最佳做法
- 2. SharePoint列表最佳做法
- 3. 从java项目创建.jar文件的最佳做法是什么?
- 4. 创建新项目的好做法
- 5. 自己做一个小项目的最佳做法
- 6. C# - 使用数组创建自定义列表的最佳做法
- 7. 从父项目创建子项目的最佳方法是什么?
- 8. 为每个列表项目创建自定义视图的最佳方式
- 9. 有关使用回调创建方法的最佳做法
- 10. 目录轮询的最佳做法
- 11. 尝试编辑不存在的项目的最佳做法?
- 12. 最佳做法在新的web项目上的JavaScript配置
- 13. 命令行构建的最佳做法
- 14. 在项目控件的项目之间共享属性的最佳做法
- 15. 创建动态选择(下拉)列表的最佳方法?
- 16. 转发项目的最佳做法来源
- 17. 分叉Android应用程序/项目的最佳做法
- 18. 开始新项目时的最佳做法
- 19. 单个大型SVN项目的最佳做法
- 20. 关于项目后叉版本号的Maven最佳做法
- 21. 来自多个类别最佳做法的项目
- 22. 查询项目及其链接数据的最佳做法
- 23. 异步删除ListView/RecyclerView项目的最佳做法
- 24. 为项目储存宝石的最佳做法是什么?
- 25. 在一个项目中的最佳做法webapi /网站
- 26. iOS导航添加项目的最佳做法
- 27. 在html.erb文件中显示localStorage项目的最佳做法
- 28. 编写阵列的最佳做法
- 29. 存储阵列的最佳做法
- 30. 创建使用.NET命名空间的库的最佳做法
整个项目的高度是已知的还是固定的?中间的文本框每个都必须占据垂直空间的一半吗? – 2014-08-27 22:22:38