私は物理デバイスの高さ60%と幅60%のボタンを設定しようとしています。Androidで高さと幅のパーセンテージを行う方法は?
画面のサイズはユーザーによって異なるため、ディップを使用することは問題になりません。
Androidで高さと幅のパーセンテージをどのように設定できますか?例:
<Button android:layout_width="60%" android:layout_height="60%"/>
私は物理デバイスの高さ60%と幅60%のボタンを設定しようとしています。Androidで高さと幅のパーセンテージを行う方法は?
画面のサイズはユーザーによって異なるため、ディップを使用することは問題になりません。
Androidで高さと幅のパーセンテージをどのように設定できますか?例:
<Button android:layout_width="60%" android:layout_height="60%"/>
layout_weight
属性を使用できます。親のレイアウトを10ウェイトに設定している場合は、Button
に6というウェイトを設定できます。
スタックオーバーフローに関するトピックのかなりがあります:
Linear Layout and weight in Android
...または公式Androidのブログ上:
http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html
今ではと位置付けGuidelinesで可能ですパーセント値
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/horizontalGuideline"
app:layout_constraintEnd_toStartOf="@+id/verticalGuideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/verticalGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.6" />
<android.support.constraint.Guideline
android:id="@+id/horizontalGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.6" />
</android.support.constraint.ConstraintLayout>