Android 我是否可以按父项调整到某个百分比';保持高度';美国的违约率。(安卓)
我想调整到一定的百分比由家长的与保持它的默认比率 我想要Android 我是否可以按父项调整到某个百分比';保持高度';美国的违约率。(安卓),android,Android,我想调整到一定的百分比由家长的与保持它的默认比率 我想要 保持它的默认比率 按父高度将高度调整为某个百分比 我想做一个像这样的按钮。 但我有这个。 这是我的密码 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.a
- 保持它的默认比率
- 按父高度将高度调整为某个百分比
我想做一个像这样的按钮。 但我有这个。 这是我的密码
<androidx.constraintlayout.widget.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"
>
<ImageView
android:id="@android:id/icon"
android:layout_width="0dp"
android:layout_height="0dp"
android:src="..."
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@android:id/text1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintHeight_percent="0.5"
app:layout_constrainedWidth="true"
/>
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:text="..."
android:textSize="..."
app:layout_constraintLeft_toRightOf="@android:id/icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constrainedWidth="true"
/>
由于您的图像是静态的,请遵循以下路径:
通过检查图像,找出图像的比例。例如,如果图像为10 x 25,其宽高比将为2:5。在
app:layout\u constraintDimensionRatio
上使用此值。然后,您可以在一个维度上设置一个百分比值,另一个维度将自行调整以保持比率。您可以使用constraintlayouts ratio related属性来实现这一点。比率可以与百分比相结合。@Nezih Yılmaz谢谢!我知道“app:layout\u constraintDimensionRatio”,但我不知道如何用百分比设置值。我想自动保持图像的默认比率。请给我看更多的。。T.T。。我尝试了app:layout\u constraintDimensionRatio=“1:1”和app:layout\u constraintheights\u percent=“0.5”,但它只是方形的..哦,你想约束图像,而不是按钮?嗯。。当我改变图片资源时,我想自动设置比率和父母身高的一定百分比…谢谢!我想在更改图像时自动设置app:layout\u constraintDimensionRatio
。可能吗?或者我需要手动更改比率?我将图像(100x200)设置为查看并设置app:layout\u constraintDimensionRatio=“1:2”
。然后我改变图像(200x500)。。。。我必须手动更改它吗?或者我可以在xml中自动更改它吗?