比例映像布顿量适合宽度

发布于 2025-01-24 06:51:22 字数 3166 浏览 0 评论 0原文

我有一个带有约束点的卷轴,我想添加一些imageButtons。它们应该缩放以适合半宽,以便我可以连续将2个按钮放入。 整个过程必须滚动,因为我想添加大约10行按钮。 我尝试了许多选项,例如SEED ConstraintLayout:如何让视图是屏幕宽度的一半并集中?

我的Layout.xml:

<?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="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
tools:ignore="SpeakableTextPresentCheck">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:adSize="BANNER"
        app:adUnitId="ca-app-pub-xxxxxx"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/ibDog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/dog"
        app:layout_constraintEnd_toStartOf="@+id/ibHorse"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/adView"

        app:srcCompat="@drawable/dog" />

    <ImageButton
        android:id="@+id/ibHorse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/horse"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/ibDog"
        app:layout_constraintTop_toBottomOf="@+id/adView"
        app:srcCompat="@drawable/horse" />

    <ImageButton
        android:id="@+id/ibCat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/cat"
        app:layout_constraintEnd_toStartOf="@+id/ibFrog"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/ibHorse"
        app:srcCompat="@drawable/cat" />

    <ImageButton
        android:id="@+id/ibFrog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/frog"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/ibCat"
        app:layout_constraintTop_toBottomOf="@id/ibHorse"
        app:srcCompat="@drawable/frog" />


</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

谢谢!

I have a Scrollview with a ConstraintLayout and I want to add some Imagebuttons. They should be scaled to fit the half width so I can put 2 Buttons in a row.
The whole thing must me scrollable because I want to add about 10 rows of buttons.
I tried many options like seen here ConstraintLayout: how to have a view be half the screen width and centered?

My layout.xml:

<?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="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
tools:ignore="SpeakableTextPresentCheck">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:adSize="BANNER"
        app:adUnitId="ca-app-pub-xxxxxx"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/ibDog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/dog"
        app:layout_constraintEnd_toStartOf="@+id/ibHorse"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/adView"

        app:srcCompat="@drawable/dog" />

    <ImageButton
        android:id="@+id/ibHorse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/horse"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/ibDog"
        app:layout_constraintTop_toBottomOf="@+id/adView"
        app:srcCompat="@drawable/horse" />

    <ImageButton
        android:id="@+id/ibCat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/cat"
        app:layout_constraintEnd_toStartOf="@+id/ibFrog"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/ibHorse"
        app:srcCompat="@drawable/cat" />

    <ImageButton
        android:id="@+id/ibFrog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/frog"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/ibCat"
        app:layout_constraintTop_toBottomOf="@id/ibHorse"
        app:srcCompat="@drawable/frog" />


</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尝试以下内容。我已经将 scrollview 的宽度更改为match_parent,然后将 imageViews 的宽度更改为0dp,它将拉伸根据链逻辑)。

<ScrollView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    tools:ignore="SpeakableTextPresentCheck">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:id="@+id/adView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:adSize="BANNER"
            app:adUnitId="ca-app-pub-xxxxxx"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/ibDog"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toStartOf="@+id/ibHorse"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/adView"
            app:srcCompat="@drawable/ic_launcher_foreground" />

        <ImageButton
            android:id="@+id/ibHorse"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/ibDog"
            app:layout_constraintTop_toBottomOf="@+id/adView"
            app:srcCompat="@drawable/ic_launcher_foreground" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Try the following. I have changed the width of the ScrollView to match_parent and changed the width of the ImageViews to 0dp which will stretch out the images according to chain logic.

<ScrollView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    tools:ignore="SpeakableTextPresentCheck">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:id="@+id/adView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:adSize="BANNER"
            app:adUnitId="ca-app-pub-xxxxxx"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/ibDog"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toStartOf="@+id/ibHorse"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/adView"
            app:srcCompat="@drawable/ic_launcher_foreground" />

        <ImageButton
            android:id="@+id/ibHorse"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/ibDog"
            app:layout_constraintTop_toBottomOf="@+id/adView"
            app:srcCompat="@drawable/ic_launcher_foreground" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

enter image description here

携余温的黄昏 2025-01-31 06:51:22
<LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:orientation="horizontal">
                <ImageButton
                    android:id="@+id/ibHorse"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:contentDescription="@string/dog"
                    android:layout_height="wrap_content"
                    app:srcCompat="@drawable/horse" />
                <ImageButton
                    android:id="@+id/ibCat"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:contentDescription="@string/cat"
                    android:layout_height="wrap_content"
                    app:srcCompat="@drawable/cat" />
            </LinearLayout>
<LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:orientation="horizontal">
                <ImageButton
                    android:id="@+id/ibHorse"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:contentDescription="@string/dog"
                    android:layout_height="wrap_content"
                    app:srcCompat="@drawable/horse" />
                <ImageButton
                    android:id="@+id/ibCat"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:contentDescription="@string/cat"
                    android:layout_height="wrap_content"
                    app:srcCompat="@drawable/cat" />
            </LinearLayout>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文