简体   繁体   English

如何在android xml中制作这种布局

[英]How to make this kind of Layout in android xml

在此处输入图像描述

I have problem in placing image view at middle of two different Layout.我在将图像视图放置在两个不同布局的中间时遇到问题。 please help请帮忙

Try using constraint layout and fix the Image view to centre of the screen and then by using vertical bias adjust the image view to the centre of top view.尝试使用约束布局并将图像视图固定到屏幕中心,然后使用垂直偏差将图像视图调整到顶视图的中心。

Take this example:举个例子:

  <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/footerAd"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="@color/black"
            android:orientation="vertical"
            android:visibility="visible"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="-30dp"
            tools:visibility="visible" />

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@color/colorPrimary"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.498"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.198" />


    </androidx.constraintlayout.widget.ConstraintLayout>

This is achievable using ConstraintLayout: Please note the constraints of the ImageView.这可以使用 ConstraintLayout 实现:请注意 ImageView 的约束。

  <androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/container_top"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="@android:color/holo_red_light"
    app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/container_bottom"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    app:layout_constraintTop_toBottomOf="@id/container_top" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@mipmap/ic_launcher"
    app:layout_constraintBottom_toTopOf="@id/container_bottom"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/container_top" />

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM