2

ボタンを物理デバイスの高さ 60%、幅 60% に設定しようとしています。

画面のサイズはユーザーに依存するため、ディップを使用することは問題外です。

Androidで高さと幅のパーセンテージをどのように行うことができますか? 例えば:

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

2 に答える 2

2

属性を使用できlayout_weightます。親レイアウトのウェイトを 10 に設定した場合は、 でウェイトを 6 に設定できますButton

Stack Overflow のトピックにはかなりの量があります。

Android のリニア レイアウトとウェイト

... または Android の公式ブログ:

http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

于 2011-10-21T09:17:20.140 に答える
0

パーセンテージ値で配置されたガイドラインで可能になりました

レイアウトエディタ

<?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>
于 2017-11-07T06:56:35.783 に答える