ボタンを物理デバイスの高さ 60%、幅 60% に設定しようとしています。
画面のサイズはユーザーに依存するため、ディップを使用することは問題外です。
Androidで高さと幅のパーセンテージをどのように行うことができますか? 例えば:
<Button android:layout_width="60%" android:layout_height="60%"/>
属性を使用できlayout_weight
ます。親レイアウトのウェイトを 10 に設定した場合は、 でウェイトを 6 に設定できますButton
。
Stack Overflow のトピックにはかなりの量があります。
... または Android の公式ブログ:
http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html
パーセンテージ値で配置されたガイドラインで可能になりました
<?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>