比例映像布顿量适合宽度
我有一个带有约束点的卷轴,我想添加一些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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试以下内容。我已经将 scrollview 的宽度更改为
match_parent
,然后将 imageViews 的宽度更改为0dp
,它将拉伸根据链逻辑)。Try the following. I have changed the width of the ScrollView to
match_parent
and changed the width of the ImageViews to0dp
which will stretch out the images according to chain logic.