Android V7支持FrameLayout无法正确扩展

时间:2015-02-26 06:52:18

标签: android android-layout

Android布局似乎有拒绝我的倾向,我只能希望我不是唯一一个发现它们荒谬的人。

我基本上使用RelativeLayouts设计了我的界面(这似乎完全按照他们所说的去做),但我发现,它们根本不能扩展。我可以看到设计规模的唯一方法是使用大量的dimens.xml文件为各种屏幕尺寸的所有mayor输入窗口小部件提供宽度值。这不是一个完全无缝的解决方案。

所以我开始尝试使用support.v7.GridLayout。 对我而言,设计看起来不是非常强大,而是相当不稳定 - 我想在大多数情况下这是我的错,但我确切地说它失败了。 我的基本设计看起来像这样,它按预期工作:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.GridLayout
    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="match_parent"
    android:padding="10dip"
    app:columnCount="4"
    app:rowCount="4"
    >

<TextView
    style="@style/StdText"
    android:id="@+id/test_tvid_1"
    android:text="@string/txt_dummy"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_gravity="fill_horizontal"
    app:layout_column="0"
    app:layout_row="0"
    app:layout_columnSpan="4"
    android:background="#7F0000"
    />


<TextView
    style="@style/StdText"
    android:id="@+id/test_tvid_2"
    android:text="@string/txt_dummy"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_gravity="fill_horizontal"
    app:layout_column="0"
    app:layout_row="1"
    app:layout_columnWeight="1"
    android:background="#7F0000"
    />

<TextView
    style="@style/StdText"
    android:id="@+id/test_tvid_2_1"
    android:text="@string/txt_dummy"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_gravity="fill_horizontal"
    app:layout_column="1"
    app:layout_row="1"
    app:layout_columnSpan="2"
    android:background="#007F00"
    />

<TextView
    style="@style/StdText"
    android:id="@+id/test_tvid_3"
    android:text="@string/txt_dummy"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_gravity="fill_horizontal"
    app:layout_column="1"
    app:layout_row="2"
    app:layout_columnWeight="1"
    android:gravity="end"
    android:background="#007F00"
    />
<TextView
    style="@style/StdText"
    android:id="@+id/test_tvid_4"
    android:text="@string/txt_dummy"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_gravity="fill_horizontal"
    app:layout_column="2"
    app:layout_row="2"
    app:layout_columnWeight="1"
    android:gravity="end"
    android:background="#00007F"
    />
<TextView
    style="@style/StdText"
    android:id="@+id/test_tvid_5"
    android:text="@string/txt_dummy"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_gravity="fill_horizontal"
    app:layout_column="3"
    app:layout_row="2"
    app:layout_columnWeight="1"
    android:gravity="end"
    android:background="#7f007f"
    />

</android.support.v7.widget.GridLayout>

Image of the Layout

我需要做的就是破坏布局,转到TextView No. 3 id:test_tvid_2_1并将app:layout_columnSpan更改为3,这是一个有效的大小,在给定的列数为4的范围内。 会发生什么,是布局突然扩展到屏幕之外,因此第4列(colIdx 3)不再完全在屏幕上,文本实际上消失了。这发生在设备和AndroidStudio布局设计器中。 这只是触发这种行为的最简单方法。每当我添加更多“复杂”的行时,它实际上就会发生..任何人都可以指出我的错误吗? 干杯托马斯

0 个答案:

没有答案