1
PercentRelativeLayoutを使用して、希望の幅のディメンションと自動高さを指定することは可能ですか?PercentRelativeLayoutを使用して幅のみを指定する(Heigh Auto)
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/earthImageView"
app:layout_widthPercent="30%"
android:src="@drawable/earth"
android:layout_alignParentRight="true"
android:adjustViewBounds="true"/>
</android.support.percent.PercentRelativeLayout >
ビューが正しい幅を有しているが、私は、レイアウトの境界を確認する場合、私は高さがMATCH_PARENTであることがわかります。
私はこれを行うことを意味します。それはhat android:adjustViewBounds = "true"が機能していないことを意味します。
私はapp:layout_widthPercent = "WRAP_CONTENT"を追加しようとしましたが、効果はありません。
ありがとうございます。
編集:私が正しく理解していれば、あなたが幅を指定し、どんなadjustViewBoundsに自動的に設定され、高さはあなたを与えるしたい
<ImageView
android:id="@+id/earthImageView"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_heightPercent="20%"
android:src="@drawable/earth"
android:adjustViewBounds="true"/>
感謝を!動作するようです! – NullPointerException
私は幅の代わりに高さのパーセントでそれを試してみると...私は同じエラーがあります。質問に新しい問題を追加しました。どうすればテストできますか? – NullPointerException
これはいい質問です@NullPointerException、それも動作するように見えることはできません。あなたのイメージの比率を知っていますか?もしあなたがlayout_width(とlayout_height)を削除し、 'app:layout_aspectRatio = "80%"'例えば – mVck