简体   繁体   English

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

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

doing this layer work and can't figure out how to put layers below ones I made when the android orientation is horizontal, it keeps pushing my layer to the outsidie I have a pics what I have done and how it has to look, if you have any ideas would be nice to hear, thank you in advance.当 android 方向为水平时,我无法弄清楚如何将图层放在我制作的图层下方,它不断将我的图层推向外部我有一张我所做的照片以及它的外观,如果你有任何想法会很高兴听到,提前谢谢你。 How it has to look它的外观
and What I have done我做了什么

<?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>

If you are using you should use these attribute to control the position如果您正在使用,您应该使用这些属性来控制 position

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

based on what it should look like, you can try根据它应该是什么样子,你可以尝试

<?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>

it should look like this它应该看起来像这样

在此处输入图像描述

Use 2 seperate LinearLayout one below other in root.在根目录下使用 2 个单独的 LinearLayout 一个。 One for horigontal views.一个用于水平视图。 Second for vertical views.其次是垂直视图。 And use weight_sum property in LinearLayout, along with weight property in child views to distribute child views eqally.并使用 LinearLayout 中的weight_sum属性,以及子视图中的weight属性来平均分配子视图。

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

相关问题 水平列表视图一个低于另一个android - Horizontal listview one below the other android 在 Android Studio 中为每个方向设置不同的约束 - Set different constraints for each orientation in Android Studio Android Studio布局-在同一行上彼此相邻的两个textview的父级中水平居中 - Android Studio Layout - Horizontal centering in parent of two textviews that are next to each other on same line Android水平方向旋转时缺少某些零件 - Android Horizontal orientation while rotation some parts missing Android:布局没有互相添加 - Android: Layouts not being added below each other Android - 垂直方向作品,水平方向空白 - Android - vertical orientation works, horizontal orientation blank 屏幕方向发生变化时,Android片段彼此重叠显示 - Android Fragments Displaying On Top Of Each Other When Screen Orientation Changes Android XML:Textview 下方有 2 个彼此相邻的 Imageview - Android XML: Textview with 2 Imageviews below it that are next to each other Android Studio:在模拟器上测试时水平滚动视图冻结 - Android Studio: Horizontal Scroll View Freezes While Testing On Emulator android:orientation=“vertical” vs android:orientation=“horizontal”之间的区别 - Difference between android:orientation=“vertical” vs android:orientation=“horizontal”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM