繁体   English   中英

Android Studio线性布局设计问题

[英]Android Studio Linear Layout Design issue

我在设计App的Android Studio布局时遇到问题。 在线性布局中,我想在第一列中水平添加前两个布局,然后在下一列中,我希望在水平中添加三个按钮,最后在最后一列中添加Listview。 任何帮助将不胜感激。 与目前一样,所有内容都排成一行。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical" >


         <james.view.VideoView
               android:id="@+id/remoteVideoView"
              android:layout_width="120dp"
             android:layout_height="90dp"
              />

        <james.view.VideoView
               android:id="@+id/localVideoView"
              android:layout_width="120dp"
              android:layout_height="90dp"
             />

             <Button
             android:id="@+id/startVideoButton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Start Call"
              />

             <Button
              android:id="@+id/stopVideoButton"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="End Call"
             />

             <Button
             android:id="@+id/sendmessage"
                 android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="msg"
             />


             <ListView
             android:id="@+id/errorList"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

        </ListView>
    </LinearLayout>

</android.support.constraint.ConstraintLayou

这就是我想要的布局

解:

这正是您想要的方式,只需复制粘贴即可完成您的工作:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <james.view.VideoView
            android:id="@+id/remoteVideoView"
            android:layout_width="120dp"
            android:layout_height="90dp"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/localVideoView"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <james.view.VideoView
            android:id="@+id/localVideoView"
            android:layout_width="120dp"
            android:layout_height="90dp"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toEndOf="@+id/remoteVideoView"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout2">

        <Button
            android:id="@+id/startVideoButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Start Call" />

        <Button
            android:id="@+id/stopVideoButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="End Call" />

        <Button
            android:id="@+id/sendmessage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="msg" />

    </LinearLayout>


    <ListView
        android:id="@+id/errorList"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout3">

    </ListView>

</android.support.constraint.ConstraintLayout>

试试吧。 希望能帮助到你。

这是一个示例xml,类似于您的图像。 由于您的代码使用constraintLayout,因此我使用constraintLayout创建了xml,而不是线性布局。 我是从设计屏幕而不是从文本屏幕创建的。 这是xml`

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="49dp"
        android:layout_marginStart="49dp"
        android:layout_marginTop="32dp"
        android:text="Button"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="67dp"
        android:layout_marginRight="67dp"
        android:layout_marginTop="32dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="193dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="@+id/button"
        app:layout_constraintStart_toStartOf="@+id/button"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="29dp"
        android:layout_marginStart="29dp"
        android:text="Button"
        app:layout_constraintBaseline_toBaselineOf="@+id/button3"
        app:layout_constraintStart_toEndOf="@+id/button3" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="35dp"
        android:layout_marginEnd="17dp"
        android:layout_marginRight="17dp"
        android:layout_marginTop="193dp"
        android:text="Button"
        app:layout_constraintBottom_toTopOf="@+id/recyclerView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="19dp"
        android:layout_marginEnd="22dp"
        android:layout_marginLeft="22dp"
        android:layout_marginRight="22dp"
        android:layout_marginStart="22dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button5" />
</android.support.constraint.ConstraintLayout>

`请查看是否对您有帮助。 根据您的要求,这不是确切的屏幕。

如果您不了解约束。 您可以使用常规的LinearLayout。

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp"
    tools:context=".MainActivity"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="90dp"
        >

        <james.view.VideoView
            android:id="@+id/remoteVideoView"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            />

        <james.view.VideoView
            android:id="@+id/localVideoView"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        >

        <Button
            android:id="@+id/startVideoButton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Start Call"/>

        <Button
            android:id="@+id/stopVideoButton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="End Call"/>

        <Button
            android:id="@+id/sendmessage"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="msg"/>

    </LinearLayout>

    <ListView
        android:id="@+id/errorList"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="10dp"
        android:layout_weight="1"
        >

    </ListView>

</LinearLayout>

非常简单!

暂无
暂无

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

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