android - 如何在 RecyclerView 项目中同时为垂直和水平创建 layout_weight
问题描述
下面是我的 XML 项目脚本:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal" android:layout_width="match_parent"
android:weightSum="1"
android:layout_height="wrap_content">
<TextView
android:id="@+id/t"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="0.5"
android:gravity="center"
android:textColor="#000000"
android:textSize="20sp"
/>
<TextView
android:id="@+id/d"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="0.5"
android:gravity="center"
android:textColor="#000000"
android:textSize="20sp"
/>
</LinearLayout>
需要进行哪些更改才能将垂直和水平权重同时应用于布局Linear Layout
?
解决方案
如果你想使用LinearLayout
你可以使用这样的东西:
[LinearLayout ] [LinearLayout ]
[child 1] [child 1](takes full screen height)
[child 2]
这是它的 XML:
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2">
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button"/>
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button" />
</LinearLayout>
</LinearLayout>
它看起来像这样:
推荐阅读
- flutter - 作为等值对象成员的等值对象列表
- asp.net-core - ASP.NET Core Web 应用程序中电子邮件确认链接的默认有效期是多少?
- css - 我不能让这个 React CSS 布局定位:固定;底部:0;正确地
- rust - 使用 Rust 的折线到点 - shapefile
- c++ - c++函数将十六进制字符串转换为uint8_t数组
- javascript - 我们如何在动态元素中自动播放下一个音频?
- r - 将动态小计添加到 Shiny DataTable
- python - numpy 跨矩阵执行条件运算
- r - 仅当 Selectinput 更改时才显示操作按钮
- git - Git手动合并问题