ScrollView“内部”图像按钮

时间:2020-02-09 10:52:01

标签: android layout constraints imagebutton

我在Android应用中难以实现这种设计。

enter image description here

我首先拥有的是一个 ConstraintLayout ,里面有一个 ImageButton (包装他的内容)。很好。

但是我还想要一个 Horizo​​ntalScreenView ,其宽度与 ImageButton 相同,并且在他的内部有一个很大的 ImageView ,该宽度从水平位置开始 Horizo​​ntalScreenView 的中心。

代码中情况的示例 ...

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

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/example"/>

    <HorizontalScrollView
        android:layout_width="¿HERE IS THE PROBLEM?"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">

        <!-- I WANT THIS IMAGE TO START AT THE CENTER OF PARENT (HorizontalScrollView) -->
        <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="false"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/example"/>

    </HorizontalScrollView>

谢谢大家!

1 个答案:

答案 0 :(得分:0)

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/example"/>

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent">


   <LinearLayout
            android:id="@+id/llImage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:orientation="horizontal">
    <!-- This image starts at the center of parent (HorizontalScrollView) -->
    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="false"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/example"/>

   </LinearLayout>

</HorizontalScrollView>
相关问题