【发布时间】:2018-07-08 22:42:26
【问题描述】:
我在一张背景图片上放置了小图片按钮。我已经使用约束布局管理了小图像的位置。但现在,问题在于小图像按钮的大小。随着屏幕尺寸的变化,图像不会改变尺寸。
我尝试过使用 drawable-hdpi、drawable-xhdpi、drawable-xxhdpi,但可能是约束布局没有拍摄这些图像。如果我应用 layout_constraintDimensionRatio,图像会针对不同的屏幕更改其位置。还是应该使用其他方法?
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imgMainBg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:layout_centerInParent="true"
android:contentDescription="Background" />
<ImageButton
android:id="@+id/btnImg1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:contentDescription="btnImg1"
android:scaleType="fitXY"
android:src="@drawable/btnImg1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.585"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.183" />
<ImageButton
android:id="@+id/btnImg2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:contentDescription="btnImg2"
android:scaleType="centerCrop"
android:src="@drawable/btnImg2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.944"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.352" />
</android.support.constraint.ConstraintLayout>
【问题讨论】:
标签: android android-layout android-constraintlayout