如何添加ImageButtons到ScrollView?
如果我试图添加ImageButton来布局,它似乎没有任何东西。任何人都可以帮助我?我尝试了一切,但它不起作用。 这里是代码: .XML:如何添加ImageButtons到ScrollView?
<ImageButton android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/categories_action"
app:layout_constraintStart_toStartOf="@+id/scrollView2"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView2"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/cat_iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/categories_first_background" />
</RelativeLayout>
</ScrollView>
背景是1080×1920图像
回答:
的ImageButton不能被显示,因为你的滚动型位于上方的ImageButton。 您需要将ImageButton放置在ScrollView或ScrollView下面。
回答:
试试这个
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollView2"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:background="@android:color/transparent"
android:layout_above="@+id/cat_iv1"
android:scaleType="fitCenter"
android:src="@drawable/categories_action"/>
<ImageView
android:id="@+id/cat_iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:clickable="true"
android:src="@drawable/categories_first_background" />
</RelativeLayout>
</ScrollView>
以上是 如何添加ImageButtons到ScrollView? 的全部内容, 来源链接: utcz.com/qa/264657.html