有一个布局如下所示:从中间向两边排列。
有什么样的布局可以使用?或者那种view的属性可以这样设置

解决方案 »

  1.   

    通过设置LinearLayout为        android:gravity="center"
            android:orientation="horizontal"
    就可以了,下面是我实现的代码
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.zth.eight.EightActivity"
        android:orientation="vertical">    <LinearLayout
            android:gravity="center"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="100dp">        <ImageView
                android:src="@mipmap/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />        <ImageView
                android:src="@mipmap/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />        <ImageView
                android:src="@mipmap/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />        <ImageView
                android:src="@mipmap/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />    </LinearLayout>    <LinearLayout
            android:gravity="center"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="100dp">        <ImageView
                android:src="@mipmap/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />        <ImageView
                android:src="@mipmap/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>    <LinearLayout
            android:gravity="center"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="100dp">        <ImageView
                android:src="@mipmap/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />        <ImageView
                android:src="@mipmap/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />        <ImageView
                android:src="@mipmap/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />        <ImageView
                android:src="@mipmap/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />    </LinearLayout></LinearLayout>
      

  2.   

    一楼方法当图片很多时或不确定时是没办法实现的。
    不过,可以在那个基础上改进一下,用代码动态添加。
    或者,用tableLayout试试,方法肯定不止一个。
      

  3.   

    如果不是动态布局的话用ConstraintLayout 这种布局方式可以解决,如果动态生成的话可以用View占位的方式可以实现
      

  4.   

    我也来说一种
    RelativeLayout
        RelativeLayout
        RelativeLayout
        RelativeLayout
    RelativeLayout
    每个都垂直居中,万能的哈