屏幕按比例分成2X2方格,布局怎么弄,要求根据不同分辨率自动条件

Android 码拜 9年前 (2015-07-18) 977次浏览
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:orientation="vertical" >

	<LinearLayout
		android:orientation="horizontal"
		android:layout_width="fill_parent"
		android:layout_height="0dp"
		android:layout_weight="1"
		android:baselineAligned="false"
		>
		<LinearLayout
			android:layout_width="0dp"
			android:layout_height="fill_parent"
			android:layout_weight="1"
			android:background="#ff999999"
			android:orientation="vertical"
			>
		</LinearLayout>
		<LinearLayout
			android:layout_width="0dp"
			android:layout_height="fill_parent"
			android:layout_weight="1"
			android:background="#ff666666"
			android:orientation="vertical"
			>
		</LinearLayout>
	</LinearLayout>
	<LinearLayout
		android:orientation="horizontal"
		android:layout_width="fill_parent"
		android:layout_height="0dp"
		android:layout_weight="1"
		android:baselineAligned="false"
		>
		<LinearLayout
			android:layout_width="0dp"
			android:layout_height="fill_parent"
			android:layout_weight="1"
			android:background="#ffbbbbbb"
			android:orientation="vertical"
			>
		</LinearLayout>
		<LinearLayout
			android:layout_width="0dp"
			android:layout_height="fill_parent"
			android:layout_weight="1"
			android:background="#ffdddddd"
			android:orientation="vertical"
			>
		</LinearLayout>
	</LinearLayout>
</LinearLayout>

#1

这个样子,但是老是有“nested weights are bad for performance”提示,因为layout——weight 好像不提倡嵌套,可是这种布局不嵌套layout_weight 怎么搞?
屏幕按比例分成2X2方格,布局怎么弄,要求根据不同分辨率自动条件

40分

#2

TableLayout不行么

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent" android:layout_column="2">

    <TableRow
            android:layout_width="match_parent"
            android:layout_weight="1">
        <TextView android:layout_weight="1" android:layout_height="match_parent" android:background="#ff0000"/>
        <TextView android:layout_weight="1" android:layout_height="match_parent" android:background="#00ff00"/>
    </TableRow>
    <TableRow
            android:layout_width="match_parent"
            android:layout_weight="1">
        <TextView android:layout_weight="1" android:layout_height="match_parent" android:background="#0000ff"/>
        <TextView android:layout_weight="1" android:layout_height="match_parent" android:background="#e3e3e3"/>
    </TableRow>
</TableLayout>

#3

回复2楼:

这个样子,但是老是有“nested weights are bad for performance”提示,因为layout——weight 好像不提倡嵌套,可是这种布局不嵌套layout_weight 怎么搞?
屏幕按比例分成2X2方格,布局怎么弄,要求根据不同分辨率自动条件

O,只用 LinearLayout 和FrameLayout,忘了还有TableLayout,最外层换成 TableLayout 和TableRow后,提示就没有了。

#4

用相对布局不行吗新手

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明屏幕按比例分成2X2方格,布局怎么弄,要求根据不同分辨率自动条件
喜欢 (0)
[1034331897@qq.com]
分享 (0)