ピクセルではなく画面の幅と高さのパーセンテージに基づいて、TextView または関連要素の XML ベースの位置を調整することは可能ですか? たとえば、
android:layout-marginLeft="150dip"
のようなものに置き換えられます
android:layout-marginLeft="25%"?
そうでない場合、プログラムで行うことは可能ですか?
ピクセルではなく画面の幅と高さのパーセンテージに基づいて、TextView または関連要素の XML ベースの位置を調整することは可能ですか? たとえば、
android:layout-marginLeft="150dip"
のようなものに置き換えられます
android:layout-marginLeft="25%"?
そうでない場合、プログラムで行うことは可能ですか?
属性はlayout_margin
パーセント値を受け入れません。
パーセンテージを使用してレイアウトを定義できるLinearLayout
属性を探しています。android:layout_weight
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".75" />
</LinearLayout>
この例では、左TextView
が画面の 25% を使用し、右がTextView
75% を使用しています。
PercentRelativeLayout を使用します ( http://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html )
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="25%"
app:layout_marginLeftPercent="25%"/>
</android.support.percent.PercentFrameLayout>