2017-08-15 7 views
2
<?xml version="1.0" encoding="utf-8"?> 

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    <Button 
     android:id="@+id/btn1" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" /> 

    <Button 

     android:id="@+id/btn2" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@+id/btn1"/> 

    <Button 
     android:id="@+id/btn2" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@+id/btn1"/> 

     <!--x7--> 

私は7つのボタンを相対位置に配置します。そして、私は画面に合わせて同じサイズに '幅'を調整したいと思います。私はあなたが親としてLinearLayoutを使用することができますし、画面全体にフィットすることができないか、それがデバイスに基づいて画面を超える可能性が相対的なレイアウトを使用して、それを達成するためにweightweightsumを与えることができますRelativeLayoutでの自動スケーリングボタンの幅

+0

親としてrelativeLayoutを入れる必要がありますか? –

+0

android:layout_width = "match_parent"は機能しませんか? – Vega

+0

私がrelativeLayoutなしでそれを行うことができるなら、私はrelativeLayoutを親として置かないでしょう。 –

答えて

2

を何をすべき。

あなたはscrollviewを使用し、その後、各ボタン(高さ= match_parent)を表示することを考えているならあなたは、以下のような

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="horizontal" 
       android:layout_width="match_parent" 
       android:weightSum="7" 
       android:layout_height="match_parent"> 
    <Button 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 

    <Button 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 
+0

私はそれを得ました!ご協力ありがとうございました。 –

+0

ようこそ、あなたの問題を解決したと感じる場合は、答えとしてマークすることができます。 –

0

を使用してのLinearLayoutこれを達成することができます。私はこれが助けてくれることを願っています