Android:如何在xml中平衡GridLayout

肮脏的

我想有一个带有页眉和页脚以及四个图片(ImageView)的布局,它们的大小在中间的两行两列中都相同。我不想使用GridView。

这就是我的想法:

页眉和页脚,中间有四个ImageView块(它们当前是按钮)

GridLayout元素会按照自己的方式使用大小,并且不会缩小到周围元素所施加的大小。它们要么变得太大而离开页面,要么被以下LinearLayout裁剪。这是我的意思的示例:

Nexus 5上的屏幕截图

我想您需要查看xml:

<?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="match_parent"
android:orientation="vertical"
android:weightSum="3" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical" >
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_column="1"
            android:layout_columnSpan="2"
            android:layout_gravity="fill_vertical|fill_horizontal"
            android:layout_row="0"
            android:layout_weight="1"
            android:columnCount="2"
            android:weightSum="4"
            android:rowCount="2" >

    <Button
        android:id="@+id/button2"
        android:layout_column="0"
        android:layout_row="0"
        android:layout_gravity="fill_vertical|fill_horizontal"
    android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/button13"
        android:layout_column="1"
        android:layout_row="0"
        android:layout_gravity="fill_vertical|fill_horizontal"
    android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/button14"
        android:layout_column="0"
        android:layout_row="1"
        android:layout_gravity="fill_vertical|fill_horizontal"
    android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/button15"
        android:layout_column="1"
        android:layout_row="1"
        android:layout_gravity="fill_vertical|fill_horizontal"
    android:layout_weight="1"
        android:text="Button" />

        </GridLayout>
    </LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical" >
</LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">
    </LinearLayout>

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

我想:

  • 页眉和页脚
  • 四张相同大小的居中图片
  • 四张图框周围的左右边缘。

也许我对此采取了错误的方法,所以如有必要,请随时将我送往新的方向。

Pratik Butani

没有GridView您可以尝试:

完美的作品。

<?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="match_parent"
    android:orientation="vertical"
    android:weightSum="3" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal" >

                <Button
                    android:id="@+id/button2"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="fill_vertical|fill_horizontal"
                    android:layout_row="0"
                    android:layout_weight="1"
                    android:text="Button" />

                <Button
                    android:id="@+id/button13"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="fill_vertical|fill_horizontal"
                    android:layout_row="0"
                    android:layout_weight="1"
                    android:text="Button" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="horizontal" >

                <Button
                    android:id="@+id/button14"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="fill_vertical|fill_horizontal"
                    android:layout_weight="1"
                    android:text="Button" />

                <Button
                    android:id="@+id/button15"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="fill_vertical|fill_horizontal"
                    android:layout_weight="1"
                    android:text="Button" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >
    </LinearLayout>

</LinearLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在数组Matlab中平衡唯一值

来自分类Dev

如何在此递归函数中平衡这些括号?

来自分类Dev

如何在O(log(n))中平衡此AVL树?

来自分类Dev

如何在Android中平滑画布绘制?

来自分类Dev

如何在wso2 API管理器网关中平衡websocket?

来自分类Dev

如何在GAN中平衡生成器和鉴别器的性能?

来自分类Dev

如何在带有边框的div中平衡图像位置?

来自分类Dev

如何在Python中平滑数据?

来自分类Dev

如何在MATLAB中平滑表面?

来自分类Dev

如何在Perl中平方数字?

来自分类Dev

如何在pyqtgraph中平滑图形?

来自分类Dev

如何在python中平滑曲线

来自分类Dev

如何在MATLAB中平滑表面?

来自分类Dev

如何在SQL Server中平均NVARCHAR

来自分类Dev

如何在Android活动中平铺图像并将背景色放置?

来自分类Dev

这段代码的结构是否适合其用途,如何在Android中平滑动画?

来自分类Dev

该代码的结构是否适合其用途,并且如何在Android中平滑动画?

来自分类Dev

如何在Android活动中平铺图像并将背景色放置?

来自分类Dev

在Google Cloud中平衡Websocket连接的负载

来自分类Dev

如何在HTML中平稳地垂直*插入* div?

来自分类Dev

如何在Python dict中平均相同键的值

来自分类Dev

如何在熊猫数据中平整每n行

来自分类Dev

如何在python3中平滑线条?

来自分类Dev

如何在julia中的元组中平铺命名的元组?

来自分类Dev

如何在c#中平滑线(点数组)?

来自分类Dev

如何在处理中平均更多帧的值

来自分类Dev

如何在Unity3D中平稳跳跃

来自分类Dev

如何在 QtOpenGL 中平移和缩放顶点线

来自分类Dev

如何在R中平均2个时间序列?

Related 相关文章

热门标签

归档