android - 实现这个布局

标签 android android-layout

我想实现这样的布局:

enter image description here

我能找到的最近的是:

enter image description here

目前的布局是这样的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerInParent="true"
    android:layout_centerVertical="true"
    android:baselineAligned="true"
    android:orientation="vertical"
    android:weightSum="4" >

    <LinearLayout

        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:paddingBottom="8dip" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/myimage" />
    </LinearLayout>

    <LinearLayout

        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:paddingBottom="8dip" 

        >

        <ImageButton

            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/myimage" 

            />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/myimage" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/myimage" />
    </LinearLayout>

    <LinearLayout

        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:paddingBottom="8dip" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/myimage" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/myimage" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/myimage" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:paddingBottom="8dip" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/myimage" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/myimage" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/myimage" />
    </LinearLayout>

</LinearLayout>

如何设计上面的布局?

最佳答案

创建三个方向设置为垂直且布局权重相等的线性布局。每个线性布局的 subview 也必须具有相等的布局权重。将第一个和第三个线性布局的重力设置为 center_vertical。

关于android - 实现这个布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21351225/

相关文章:

android - 应用在 9patch 背景上时,波纹效果 drawable 会失真

java - Android 应用程序因两个 Activity 崩溃

android - 如何使用 1 个 GradientDrawable xml 资源制作 10 个具有 10 个不同边框角半径的 ImageView

android - 如何使 WRAP_CONTENT 在 RecyclerView 上工作

android - 在 CardView 包含的 RelativeLayout 上设置 onClickListener

android - 哪个 LayoutManager 用于 2048 游戏的动画?

android - 迁移到 gradle kotlin dsl 后 Unresolved buildSrc kotlin 常量引用

android - 在 adt 20 中关闭 logcat 中的换行符

android - 在播放视频和相机预览时在 Android 手机上捕获屏幕截图

android - 用于小屏幕尺寸的 dimen.xml 的值文件夹