繁体   English   中英

Android Studio 层在彼此下方,方向为水平

[英]Android Studio layer below each other while orientation is horizontal

当 android 方向为水平时,我无法弄清楚如何将图层放在我制作的图层下方,它不断将我的图层推向外部我有一张我所做的照片以及它的外观,如果你有任何想法会很高兴听到,提前谢谢你。 它的外观
我做了什么

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity2">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal">


        <TextView

            android:layout_width="140dp"
            android:layout_height="300dp"
            android:background="#FA0000" />


        <TextView
            android:layout_width="140dp"
            android:layout_height="300dp"
            android:background="#03ED0F" />

        <TextView
            android:id="@+id/blue"
            android:layout_width="140dp"
            android:layout_height="300dp"
            android:background="#0027C3"
            />

        <TextView
            android:layout_below="@id/blue"
            android:layout_width="100dp"
            android:layout_height="10dp"
            android:background="#000000" />




    </LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

如果您正在使用,您应该使用这些属性来控制 position

app:layout_constraintTop_toBottomOf
app:layout_constraintTop_toTopOf
app:layout_constraintTop_toStartOf
app:layout_constraintTop_toRightOf

根据它应该是什么样子,你可以尝试

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<LinearLayout
    android:id="@+id/ll_horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent">


    <TextView
        android:layout_width="140dp"
        android:layout_height="300dp"
        android:background="#FA0000" />


    <TextView
        android:layout_width="140dp"
        android:layout_height="300dp"
        android:background="#03ED0F" />

    <TextView
        android:layout_width="140dp"
        android:layout_height="300dp"
        android:background="#0027C3"
        />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="vertical"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@id/ll_horizontal"
    app:layout_constraintBottom_toBottomOf="parent">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#FA0000" />


    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#03ED0F" />

    <TextView
        android:id="@+id/blue"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#0027C3"
        />
</LinearLayout>

它应该看起来像这样

在此处输入图像描述

在根目录下使用 2 个单独的 LinearLayout 一个。 一个用于水平视图。 其次是垂直视图。 并使用 LinearLayout 中的weight_sum属性,以及子视图中的weight属性来平均分配子视图。

暂无
暂无

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

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