Android简单百分比布局?

Android简单百分比布局?,android,android-layout,Android,Android Layout,有没有一种方法可以在安卓系统上拥有一个包含元素的全屏行? 我试着用table、GridView和linear来做这件事,但很长一段时间以来我一直在努力,找不到一篇对我有帮助的帖子 我只是画了一张我想做的小照片: 简而言之: 标签和按钮应该与内容一样大,并且适合列中最大的标签 按钮应该贴在右边 标签应该贴在左边 文本框应该只填充标签/按钮之间的剩余空间,但如果内容更大,它不应该“踢出”右侧的按钮 我最后一次尝试是GridView,它看起来是可以接受的,但不是真的 <RelativeLa

有没有一种方法可以在安卓系统上拥有一个包含元素的全屏行? 我试着用table、GridView和linear来做这件事,但很长一段时间以来我一直在努力,找不到一篇对我有帮助的帖子

我只是画了一张我想做的小照片:

简而言之:

  • 标签和按钮应该与内容一样大,并且适合列中最大的标签

  • 按钮应该贴在右边

  • 标签应该贴在左边

  • 文本框应该只填充标签/按钮之间的剩余空间,但如果内容更大,它不应该“踢出”右侧的按钮

我最后一次尝试是GridView,它看起来是可以接受的,但不是真的

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Add nutrition part"
                android:id="@+id/textView"
                android:layout_column="0"
                android:layout_row="0"
                android:layout_columnSpan="1"
                android:layout_rowSpan="1" />

            <TextView
                android:text="Selected part"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/textView15"
                android:layout_column="0"
                android:layout_row="1"
                android:layout_columnSpan="1"
                android:layout_rowSpan="1" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:text=""
                android:enabled="false"
                android:id="@+id/dialogMakeMealPartNutrition"
                android:layout_column="1"
                android:layout_row="1"
                android:layout_columnSpan="1"
                android:layout_rowSpan="1"
                android:layout_gravity="fill_horizontal" />

            <Button
                android:text="Find nutrition"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/buttonMakeMealPartFindNutrition"
                android:layout_column="2"
                android:layout_row="1"
                android:layout_columnSpan="1"
                android:layout_rowSpan="1" />

            <TextView
                android:text="Gram"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/textView17"
                android:layout_column="0"
                android:layout_row="2"
                android:layout_columnSpan="1"
                android:layout_rowSpan="1" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="numberDecimal"
                android:id="@+id/dialogMakeMealPartGram"
                android:layout_column="1"
                android:layout_row="2"
                android:layout_columnSpan="1"
                android:layout_rowSpan="1"
                android:layout_gravity="fill_horizontal" />

            <Button
                android:text="Abort"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/dialogMakeMealPartButtonAbort"
                android:layout_column="0"
                android:layout_row="3"
                android:layout_columnSpan="1"
                android:layout_rowSpan="1" />

            <Button
                android:text="Add"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/dialogMakeMealPartButtonAdd"
                android:layout_column="1"
                android:layout_row="3"
                android:layout_columnSpan="1"
                android:layout_rowSpan="1" />

        </GridLayout>

    </ScrollView>

</RelativeLayout>

编辑:

对于我来说,你做得很好-谢谢你的提示卢卡:

代码现在看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#FFFFFF">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="Add nutrition part"
                android:id="@+id/headline"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:text="Selected part"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/textView15"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/buttonMakeMealPartFindNutrition" />

            <EditText
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:text=""
                android:enabled="false"
                android:id="@+id/dialogMakeMealPartNutrition"
                app:layout_constraintStart_toEndOf="@+id/textView15"
                app:layout_constraintEnd_toStartOf="@+id/buttonMakeMealPartFindNutrition"
                app:layout_constraintTop_toTopOf="@+id/buttonMakeMealPartFindNutrition" />

            <Button
                android:text="Find nutrition"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/buttonMakeMealPartFindNutrition"
                app:layout_constraintTop_toBottomOf="@+id/headline"
                app:layout_constraintStart_toEndOf="@+id/dialogMakeMealPartNutrition"
                app:layout_constraintEnd_toEndOf="parent" />

            <TextView
                android:text="Gram"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/textView17"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/dialogMakeMealPartNutrition" />

            <EditText
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:inputType="numberDecimal"
                android:id="@+id/dialogMakeMealPartGram"
                app:layout_constraintStart_toStartOf="@+id/dialogMakeMealPartNutrition"
                app:layout_constraintEnd_toEndOf="@+id/dialogMakeMealPartNutrition"
                app:layout_constraintTop_toBottomOf="@+id/dialogMakeMealPartNutrition" />

            <Button
                android:text="Abort"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/dialogMakeMealPartButtonAbort"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/dialogMakeMealPartGram" />

            <Button
                android:text="Add"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/dialogMakeMealPartButtonAdd"
                app:layout_constraintStart_toEndOf="@+id/dialogMakeMealPartButtonAbort"
                app:layout_constraintTop_toBottomOf="@+id/dialogMakeMealPartGram" />

        </android.support.constraint.ConstraintLayout>

    </ScrollView>

</RelativeLayout>

您可以使用来实现这一点,您可以找到它的解释

布局文件应如下所示:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Add nutrition part"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/textView15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Selected part"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"/>

    <EditText
        android:id="@+id/dialogMakeMealPartNutrition"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:enabled="false"
        android:inputType="text"
        app:layout_constraintStart_toEndOf="@+id/textView15"
        app:layout_constraintEnd_toStartOf="@+id/buttonMakeMealPartFindNutrition"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        android:text=""/>

    <Button
        android:id="@+id/buttonMakeMealPartFindNutrition"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        app:layout_constraintStart_toEndOf="@+id/dialogMakeMealPartNutrition"
        app:layout_constraintEnd_toEndOf="parent"
        android:text="Find nutrition"/>

    ...

</android.support.constraint.ConstraintLayout>

...
您可以使用来实现这一点,您可以找到它的解释

布局文件应如下所示:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Add nutrition part"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/textView15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Selected part"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"/>

    <EditText
        android:id="@+id/dialogMakeMealPartNutrition"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:enabled="false"
        android:inputType="text"
        app:layout_constraintStart_toEndOf="@+id/textView15"
        app:layout_constraintEnd_toStartOf="@+id/buttonMakeMealPartFindNutrition"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        android:text=""/>

    <Button
        android:id="@+id/buttonMakeMealPartFindNutrition"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        app:layout_constraintStart_toEndOf="@+id/dialogMakeMealPartNutrition"
        app:layout_constraintEnd_toEndOf="parent"
        android:text="Find nutrition"/>

    ...

</android.support.constraint.ConstraintLayout>

...

您是否使用网格布局或其他方式实现了目标不,没有成功(或者我不知道怎么做,我猜),我尝试了网格布局,但是这个按钮被滚动了,我无法让文本框只填充剩余空间
。。。只需填充剩余空间
然后使用
match_parent
而不是
wrap_content
哪个文本需要剩余空间提及特定id的match_parent是整个屏幕的大小,按钮会被踢出然后你是否使用网格布局或其他方式实现目标不,没有工作(或者我不知道如何,我猜),我尝试了GridLayout,但是这个按钮被滚动掉了,我无法让文本框只填充剩余的空间
。。。只需填充剩余空间
然后使用
match_parent
而不是
wrap_content
哪个文本需要剩余空间提及特定id的匹配父项是整个屏幕的大小,然后按钮被踢出