【发布时间】:2015-06-18 15:00:02
【问题描述】:
我有以下以编程方式编写的代码,
Display display = this.WindowManager.DefaultDisplay;
Point size = new Point();
int height = size.Y;
bViewLayout.Height = (int)(height * 0.5);
但是,我想知道如何在 Xml 中实现屏幕的一半而不是硬编码如下?
<GridLayout
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:layout_rowSpan="1"
android:layout_height="135"/>
已编辑: 以下代码不起作用:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="2"
android:rowCount="2">
<GridLayout
android:id="@+id/aView"
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:layout_rowSpan="2"
android:layout_width="100"
android:layout_height="25"
android:text="1" />
<GridLayout
android:id="@+id/bView"
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:layout_rowSpan="1"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="0.5"
android:text="2" />
<GridLayout
android:id="@+id/cView"
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:layout_rowSpan="1"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="0.5"
android:text="3" />
</GridLayout>
【问题讨论】: