【问题标题】:Android: how to align 2 images one in center and one in bottomAndroid:如何将两张图片对齐一张在中心和一张在底部
【发布时间】:2018-04-20 16:08:23
【问题描述】:

如何使用 LinearLayout 对齐两张图片,一张居中,一张居下
因为我发现 RelativeLayout 标记为 legacy

这里的问题,但对于闪屏 Android: how to align 2 images on a splash screen

【问题讨论】:

  • 这个问题有什么更新吗?

标签: android


【解决方案1】:
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:adjustViewBounds="true"
        android:layout_weight="1"
        android:src="@drawable/image_1"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="100dp"
        android:src="@drawable/image_2"/>
</LinearLayout>

【讨论】:

    【解决方案2】:
    <?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"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    
        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="89dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="100dp"
            android:layout_marginTop="190dp"
            android:layout_weight="1"
            app:srcCompat="@drawable/child_big" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="100dp"
            app:srcCompat="@android:drawable/btn_star" />
    
    
    
    </LinearLayout>
    

    使用 marginBottom 和 marginTop 属性!

    【讨论】:

      【解决方案3】:

      如何对齐两张图片,一张居中,一张居下 线性布局

      对于LinearLayout,您可以将orientation设置为垂直

      要使图像居中,请使用android:layout_gravity="center_horizontal"

      代码

         <?xml version="1.0" encoding="utf-8"?>
         <LinearLayout
              xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:orientation="vertical"
              android:layout_height="wrap_content"
              android:layout_width="match_parent">
      
          <ImageView
                  android:layout_marginTop="90dp"
                  android:layout_gravity="center_horizontal"
                  android:layout_width="200dp"
                  android:layout_height="200dp"
                  android:background="@drawable/image"/>
      
          <ImageView
                  android:layout_marginTop="30dp"
                  android:layout_gravity="center_horizontal"
                  android:layout_width="70dp"
                  android:layout_height="70dp"
                  android:background="@drawable/image2"/>
      </LinearLayout>
      

      输出

      【讨论】:

        猜你喜欢
        • 2016-06-14
        • 1970-01-01
        • 1970-01-01
        • 2021-02-28
        • 2022-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多