Android 实现此布局的最佳视图(在屏幕中以比率或百分比表示尺寸)
您建议使用什么视图在Android中完成此布局:Android 实现此布局的最佳视图(在屏幕中以比率或百分比表示尺寸),android,android-layout,android-widget,Android,Android Layout,Android Widget,您建议使用什么视图在Android中完成此布局: --------------------------------------- | Cell 1 | | ----------------------------- Cell 4 | | Cell 2 | Cell 3 | | --------------------------------------- 单元格的内容是标题和小文本。单元格2和3的大
---------------------------------------
| Cell 1 | |
----------------------------- Cell 4 |
| Cell 2 | Cell 3 | |
---------------------------------------
单元格的内容是标题和小文本。单元格2和3的大小和宽度应与单元格1相同。单元格1应为屏幕大小的3/4,单元格4应为屏幕大小的1/4。
<LinearLayout
android:orientation="horizontal">
<LinearLayout
android:orientation="vertical>
Create cell1
<LinearLayout
android:orientation="horizontal">
Create cell 2
Create cell 3
</LinearLayout>
</LinearLayout>
Create cell 4
</LinearLayout>
我建议使用GridLayout
:
<GridLayout
android:orientation="horizontal"
android:columnCount="2"
android:rowCount="3" >
<YourCell1View
android:layout_rowSpan="2"/>
<YourCell2View
android:layout_column="1" />
<YourCell3View
android:layout_column="1"
android:layout_row="1" />
<YourCell4View
android:layout_row="2"
android:layout_columnSpan="2" />
</GridLayout>
当然,这只是一个基本布局,您必须将其余的单元视图布局添加到此布局中。但这会给你结果
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp" <!--choose height according to you need-->
android:orientation="horizontal"
android:weightSum="10">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="7"
android:orientation="vertical"
android:weightSum="10">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="@android:color/holo_blue_light" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="horizontal"
android:weightSum="10">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:background="@android:color/holo_green_dark" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:background="@android:color/holo_green_light" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="@android:color/holo_red_light" />
</LinearLayout>
给你格拉德尔
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="200dp">
<View
android:id="@+id/vwCell4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="@android:color/holo_red_dark"
app:layout_widthPercent="30%" />
<View
android:id="@+id/vwCell1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/vwCell4"
android:background="@android:color/holo_orange_dark"
app:layout_heightPercent="50%"
app:layout_widthPercent="70%" />
<View
android:id="@+id/vwCell2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/vwCell1"
android:background="@android:color/holo_green_light"
app:layout_heightPercent="50%"
app:layout_widthPercent="35%" />
<View
android:id="@+id/vwCell3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/vwCell1"
android:layout_toLeftOf="@id/vwCell4"
android:layout_toRightOf="@id/vwCell2"
android:background="@android:color/holo_blue_dark"
app:layout_heightPercent="50%"
app:layout_widthPercent="35%" />
</android.support.percent.PercentRelativeLayout>
第1单元和第4单元的b/w比率是多少@ThommyWell,你可以通过使用1.)带列和行跨度的GridView 2.)RelativeLayout 3.)带布局权重或百分比库的嵌套线性布局我同意@Robininzenz你可以很容易地使用3.)嵌套线性布局通过这种方式我遇到了问题,文本被剪切掉了。哪个文本被剪切掉了?我的意思是哪个单元格?你可以指定eg的权重-对于第一个线性布局,单元格2和3中的文本权重为3和1。你的单元格2和单元格3的合并大小应该是屏幕的3/4,对吗?第二单元和第三单元将是3/8。如果您使用上述建议的方法,它将创建您所需的布局。文本被剪切是另一个问题。
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="200dp">
<View
android:id="@+id/vwCell4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="@android:color/holo_red_dark"
app:layout_widthPercent="30%" />
<View
android:id="@+id/vwCell1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/vwCell4"
android:background="@android:color/holo_orange_dark"
app:layout_heightPercent="50%"
app:layout_widthPercent="70%" />
<View
android:id="@+id/vwCell2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/vwCell1"
android:background="@android:color/holo_green_light"
app:layout_heightPercent="50%"
app:layout_widthPercent="35%" />
<View
android:id="@+id/vwCell3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/vwCell1"
android:layout_toLeftOf="@id/vwCell4"
android:layout_toRightOf="@id/vwCell2"
android:background="@android:color/holo_blue_dark"
app:layout_heightPercent="50%"
app:layout_widthPercent="35%" />
</android.support.percent.PercentRelativeLayout>