2

プログラムの上部に2つのボタンを配置して、ユーザーをさまざまなアクティビティに誘導したいと思います。フォーマットに問題があります。

画面サイズに応じてボタンが比例して伸びるようにするにはどうすればよいですか?今のところ、1つの画面サイズで問題ないように見えます。次に別の画面サイズに切り替えると、すべてがつぶれたり、引き伸ばされたりして表示されます。さまざまなScaleTypeをすべて試しましたが、違いはないようです。私も行って、Shubhayuの答えを使用して、すべての画像を正しいサイズに比例して保存しました。

これまでの私のコードは次のとおりです。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/brushed_metal_background_dark"
tools:context=".HomeActivity" >

<ImageButton
    android:id="@+id/incidentsSelect"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/incident_bar2"
    android:contentDescription="Incidents"
    android:onClick="chooseIncident"
    android:scaleType="center" />

<ImageButton
    android:id="@+id/operationalPeriodsSelect"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/operationalperiod_bar2"
    android:contentDescription="Operational Periods"
    android:onClick="chooseOperationalPeriod"
    android:scaleType="fitCenter" />

4

3 に答える 3

2

に変更android:backgroundするandroid:srcと、アスペクト比が維持されます。android:scaleType="centerInside"ボタン領域内に画像全体を合わせるために使用し、オプションで空android:adjustViewBounds=trueのスペースを削除するために使用します。例:

<ImageButton
    android:id="@+id/incidentsSelect"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:contentDescription="Incidents"
    android:onClick="chooseIncident"
    android:src="@drawable/incident_bar2"
    android:scaleType="centerInside"
    android:adjustViewBounds="true"/>

<ImageButton
    android:id="@+id/operationalPeriodsSelect"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:contentDescription="Operational Periods"
    android:onClick="chooseOperationalPeriod"
    android:src="@drawable/operationalperiod_bar2"
    android:scaleType="centerInside"
    android:adjustViewBounds="true"/>
于 2012-12-16T21:03:29.443 に答える
0

画面上部のボタンのサイズを均等にしようとしていると思います。その場合は、設定する必要がありますandroid:layout_width="0dp"

于 2012-12-16T20:35:08.973 に答える
0

android:layout_width = "wrap_content" を使用するだけです

于 2013-04-17T09:28:56.850 に答える