Android XML FrameLayout - PullRequest
       10

Android XML FrameLayout

0 голосов
/ 12 октября 2018

У меня есть XML-файл, описывающий мою альбомную деятельность:

<?xml version="1.0" encoding="utf-8"?>

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:padding="24dp"
        android:id="@+id/question_text_view"/>

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@mipmap/img1"
        android:padding="24dp"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:orientation="horizontal">

        <Button
            android:id="@+id/trueButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/true_button" />

        <Button
            android:id="@+id/falseButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/false_button" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageButton
            android:id="@+id/prev_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/next_button"
            android:drawableRight="@drawable/arrow_left"
            android:drawablePadding="4dp"
            android:src="@drawable/arrow_left"
            android:contentDescription="arrowLeft"/>

        <ImageButton
            android:id="@+id/next_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/next_button"
                android:drawableRight="@drawable/arrow_right"
                android:drawablePadding="4dp"
                android:src="@drawable/arrow_right"
                android:contentDescription="arrowRight"/>

        </LinearLayout>

    </FrameLayout>

Я пытаюсь сделать так, чтобы предварительные и последующие кнопки ImageButton находились под trueButton и falseButton, но я не могу получить ихРабота.Я попытался:

android:layout_gravity="bottom|right"

Но это никак не повлияло на это.Для этого мне нужно использовать FrameLayout.

Это то, что он отображает в данный момент, как при запуске:

enter image description here

ЛюбойПомощь будет принята с благодарностью.Спасибо!

Кэти

Ответы [ 4 ]

0 голосов
/ 12 октября 2018

Попробуйте это:

Я использую структуру кадра следующим образом

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:padding="24dp"
    android:id="@+id/question_text_view"/>

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:src="@mipmap/ic_launcher"
    android:padding="24dp"/>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center_horizontal"
    android:orientation="vertical"
    android:layout_marginBottom="10dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/true_Button"
            android:layout_width="wrap_content"
            android:textAllCaps="false"
            android:layout_marginRight="10dp"
            android:layout_height="wrap_content"
            android:text="true" />

        <Button
            android:id="@+id/false_Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAllCaps="false"
            android:layout_marginRight="5dp"
            android:text="False" />
    </LinearLayout>

        <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center">

        <ImageButton
            android:id="@+id/prev_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="arrowLeft"/>

        <ImageButton
            android:id="@+id/next_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawablePadding="4dp"
            android:contentDescription="arrowRight"/>
    </LinearLayout>
</LinearLayout>

Я использую эту линию для изменения гравитации

android: layout_gravity = "bottom | center_hor horizontal"

вот так: enter image description here

0 голосов
/ 12 октября 2018

Добавьте линейный макет под рамкой. Макет

Попробуйте:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_gravity="center">



<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:padding="24dp"
    android:id="@+id/question_text_view"/>

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:src="@mipmap/img1"
    android:padding="24dp"/>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal"
    android:orientation="horizontal">

    <Button
        android:id="@+id/trueButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/true_button" />

    <Button
        android:id="@+id/falseButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/false_button" />
</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center">

    <ImageButton
        android:id="@+id/prev_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next_button"
        android:drawableRight="@drawable/arrow_left"
        android:drawablePadding="4dp"
        android:src="@drawable/arrow_left"
        android:contentDescription="arrowLeft"/>

    <ImageButton
        android:id="@+id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next_button"
        android:drawableRight="@drawable/arrow_right"
        android:drawablePadding="4dp"
        android:src="@drawable/arrow_right"
        android:contentDescription="arrowRight"/>

</LinearLayout>
</LinearLayout>

Output

0 голосов
/ 12 октября 2018

Попробуйте это:

<?xml version="1.0" encoding="utf-8"?>

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:padding="24dp"
        android:id="@+id/question_text_view"/>

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@mipmap/img1"
        android:padding="24dp"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                android:id="@+id/trueButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/true_button" />

            <Button
                android:id="@+id/falseButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/false_button" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal">

            <ImageButton
                android:id="@+id/prev_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/next_button"
                android:drawableRight="@drawable/arrow_left"
                android:drawablePadding="4dp"
                android:src="@drawable/arrow_left"
                android:contentDescription="arrowLeft"/>

            <ImageButton
                android:id="@+id/next_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/next_button"
                android:drawableRight="@drawable/arrow_right"
                android:drawablePadding="4dp"
                android:src="@drawable/arrow_right"
                android:contentDescription="arrowRight"/>

        </LinearLayout>
    </LinearLayout>

</FrameLayout>

output

0 голосов
/ 12 октября 2018

Я не думаю, что FrameLayout - правильный инструмент для этой работы;его возможности относительно ограничены для размещения нескольких детей по отношению друг к другу.Как правило, для этого лучше использовать что-то вроде ConstraintLayout.

Если, однако, FrameLayout является требованием, то я думаю, что единственное, что вы можете сделать, это обернуть обакнопки false и prev / next по вертикали LinearLayout, а затем по центру , что в FrameLayout.

<FrameLayout>

    <LinearLayout
        android:layout_gravity="center"
        android:orientation="vertical"
        android:gravity="center_horizontal">

        <LinearLayout
            android:orientation="horizontal">

            <Button/>

            <Button/>

        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal">

            <Button/>

            <Button/>

        </LinearLayout>

    </LinearLayout>

</FrameLayout>
...