我在Android应用中难以实现这种设计。
我首先拥有的是一个 ConstraintLayout ,里面有一个 ImageButton (包装他的内容)。很好。
但是我还想要一个 HorizontalScreenView ,其宽度与 ImageButton 相同,并且在他的内部有一个很大的 ImageView ,该宽度从水平位置开始 HorizontalScreenView 的中心。
代码中情况的示例 ...
<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>
谢谢大家!
答案 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>