ScrollView не работает должным образом с кнопками ImageButtons - PullRequest
0 голосов
/ 04 марта 2020

Я хочу, чтобы на моей домашней странице было несколько кнопок ImageButton, поэтому они должны быть в ScrollView, чтобы пользователи могли прокручивать их все. Тем не менее, это не работает, как ожидалось.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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=".Activities.HomeFragment">

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

        <ImageButton
            android:id="@+id/imageButton"
            android:layout_width="wrap_content"
            android:layout_height="216dp"
            android:background="@drawable/lunchimg" />

        <ImageButton
            android:id="@+id/lunch"
            android:layout_width="wrap_content"
            android:layout_height="216dp"
            android:background="@drawable/lunchcate" />

        <ImageButton
            android:id="@+id/dinner"
            android:layout_width="wrap_content"
            android:layout_height="216dp"
            android:background="@drawable/healthyfood" />

    </LinearLayout>
</ScrollView>

, когда я запускаю код, появляется только первая кнопка, а другие почему-то стоят за ней.

Ответы [ 3 ]

1 голос
/ 04 марта 2020

Пожалуйста, укажите ориентацию LinearLayout. Если вы не указываете какую-либо ориентацию, то по умолчанию она примет его значение как «горизонтальное».

Так вот почему вы не можете видеть свои кнопки ImageButtons.

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

<ScrollView 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=".Activities.HomeFragment">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="wrap_content"
        android:layout_height="216dp"
        android:background="@drawable/lunchimg" />

    <ImageButton
        android:id="@+id/lunch"
        android:layout_width="wrap_content"
        android:layout_height="216dp"
        android:background="@drawable/lunchcate" />

    <ImageButton
        android:id="@+id/dinner"
        android:layout_width="wrap_content"
        android:layout_height="216dp"
        android:background="@drawable/healthyfood" />
</LinearLayout>


 </ScrollView>

Надеюсь, что это будет работа

0 голосов
/ 04 марта 2020

Этот код является вашим ответом:

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="150dp">
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button One" />
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Two" />
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Three" />
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Four" />
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Five" />
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Six" />
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Seven" />
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Eight" />
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button Nine" />
    </LinearLayout>
</HorizontalScrollView>
0 голосов
/ 04 марта 2020

Вам нужно использовать утилиту просмотра, а не прокручивать. Прокрутка используется, когда вы хотите, чтобы ваш экран соответствовал различным устройствам.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...