2012-04-20 8 views
1

私は自分のためにカードックアプリケーションを作成しています。アプリケーションにショートカットを入れるための6つのボタンがあります。私は風景とポートレートモードのレイアウトを設計しました。ポートレートモードで画面サイズに問題があります。今、私は小さい画面サイズでアプリをテストする際に私がいる問題がある画面サイズに合わせて6つのボタンのサイズを変更するにはどうすればよいですか?

<Button 
    android:id="@+id/btnLaunchSlotOne" 
    style="@style/launchButton" 
    android:layout_width="fill_parent" 
    android:layout_height="100dp" 
    android:layout_weight="1" 
    android:layout_marginRight="8dp" 
    android:padding="10dp" 
    android:text="Navigation" 
    android:textColor="#ffffff" /> 

Text up here 
------------ 
| 1 | 2 | 
------------ 
| 3 | 4 | 
------------ 
| 5 | 6 | 
------------ 

はここでボタンのXMLです:私は私のアイコンがそうのように並ん持っていますボタンのサイズが変更されていないようで、画面の下部に表示されます。どうすればそれらを適切に拡大することができますか?私は "dp"を使用してすべての世話をしたと思いますか?

プログラムで画面サイズを計算する必要はありますか?

提案/助けてくれてありがとう!

答えて

3

使用正しく巣ボタンに以下のレイアウトのようなもの:次に、各ボタンは0dpの高さを必要とする

<LinearLayout 
    android:orientation="vertical"> 
    <TextView>Put your Text here</TextView> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_weightSum="2"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weightSum="3" 
      android:layout_weight="1"> 
      <Button 
       android:layout_weight="1"/> 
      <Button 
       android:layout_weight="1"/> 
      <Button 
       android:layout_weight="1"/> 
     </LinearLayout> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_weightSum="3" 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1"> 
      <Button 
       android:layout_weight="1"/> 
      <Button 
       android:layout_weight="1"/> 
      <Button 
       android:layout_weight="1"/> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

(これはすることができますウェイトは、ボタンを水平方向に適用し、拡大/縮小します)、塗りの親の幅。

トリックは、子要素のウェイトが、0dpに設定されたディメンションが親要素のweightSumの割合になるようにすることです。

たとえば、体重1の3つの子ボタンと3つの子ボタンがある線形レイアウトがあります。高さが0dpに設定されている場合、それぞれの高さは親の高さの1/3になります。 widthが0dpに設定されている場合、widthは親の幅の1/3を自分のものとみなします。

これは、幅または高さのパーセンテージに従ってアイテムを整理する最もよい方法です。

ウェイト2のボタンとウェイト1のボタンの2つがある場合は、1つのボタンは親の高さ/幅の33%、親の高さ/幅の66%になります。便利な小さなトリックとすべての画面上で動作します。

+0

これは完璧に機能し、説明に感謝します! – user1347026

+0

解決策の詳細な説明をありがとう! – ivans

2

ボタンを常にフルスクリーンで使用する場合は、GridViewを使用して、すべての画面サイズのスケーリングを自動的に処理します。

+0

here.を参照してください。グリッドレイアウトは4.0でしか利用できないと聞きましたが、GridViewを意味しますか?フルスクリーンでない場合、GridViewを使用できますか?私はこれを2.1+で開発しています – user1347026

+0

申し訳ありません、私はGridLayoutの代わりにGridViewを意味しました。はい、フルスクリーンでない場合、GridViewを使用することができます。他のビューと同じように配置およびサイズを設定することができ、すべての子がGridView全体を塗りつぶします。 – marczych

0

あなたは以下のxmlファイルを使用することができます:::

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<TextView 
android:text="Text 1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
/> 
<LinearLayout 
    android:orientation="horizantal" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:weight_sum = "2"> 
<Button android:layout_width="fill_parent" android:layout_weight="1" 
    android:layout_height="fill_parent" android:text="test" /> 
<Button android:layout_width="fill_parent" android:layout_weight="1" 
    android:layout_height="fill_parent" android:text="test" /> 
</LinearLayout> 
<LinearLayout 
    android:orientation="horizantal" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:weight_sum = "2"> 
<Button android:layout_width="fill_parent" android:layout_weight="1" 
    android:layout_height="fill_parent" android:text="test" /> 
<Button android:layout_width="fill_parent" android:layout_weight="1" 
    android:layout_height="fill_parent" android:text="test" /> 
</LinearLayout> 
<LinearLayout 
    android:orientation="horizantal" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:weight_sum = "2"> 
<Button android:layout_width="fill_parent" android:layout_weight="1" 
    android:layout_height="fill_parent" android:text="test" /> 
<Button android:layout_width="fill_parent" android:layout_weight="1" 
    android:layout_height="fill_parent" android:text="test" /> 
</LinearLayout> 


</LinearLayout> 
0

は、私は、テキストのためのボタンの上の部分を持っているしたいと思います。具体的Dashboard Layout

関連する問題