Ank*_*wal 0 java android view android-gridlayout
我试图将屏幕划分为4个相等的部分,但是遇到了问题.
<GridLayout
android:rowCount="2"
android:columnCount="2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:background="@drawable/rectangle"
android:layout_column="0"
android:layout_row="0"
/>
<View
android:background="@drawable/rectangle"
android:layout_column="1"
android:layout_row="0"
/>
<View
android:background="@drawable/rectangle"
android:layout_column="0"
android:layout_row="1"
/>
<View
android:background="@drawable/rectangle"
android:layout_column="1"
android:layout_row="1"
/>
Run Code Online (Sandbox Code Playgroud)
而rectangle.xml文件是
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview_background_shape">
<stroke android:width="2dp" android:color="#ff207d94" />
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp" />
<corners android:radius="20dp" />
<solid android:color="#ffffffff" />
</shape>
Run Code Online (Sandbox Code Playgroud)
现在矩形正在屏幕之外,第一列填满整个屏幕.
启动API 21,您可以在GridLayout中使用权重:
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:rowCount="2">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/rectangle"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/rectangle"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/rectangle" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/rectangle" />
</GridLayout>
Run Code Online (Sandbox Code Playgroud)
如果您需要支持以前的apis,请使用android.support.v7.widget.GridLayout
| 归档时间: |
|
| 查看次数: |
3434 次 |
| 最近记录: |