2011-10-21 15 views
1

私は物理デバイスの高さ60%と幅60%のボタンを設定しようとしています。Androidで高さと幅のパーセンテージを行う方法は?

画面のサイズはユーザーによって異なるため、ディップを使用することは問題になりません。

Androidで高さと幅のパーセンテージをどのように設定できますか?例:

<Button android:layout_width="60%" android:layout_height="60%"/> 

答えて

0

今ではと位置付けGuidelinesで可能ですパーセント値

Layout Editor

<?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> 
関連する問題