2017-10-13 4 views
0

3 * 4(l * b)レイアウトの円形ボタンの作成方法は?グリッドレイアウトの円形ボタン4 * 3レイアウト

Androidスタジオで円形のボタンレイアウトを表示しているコードを試しました。しかし、電話で実行すると、サイズは圧縮されます。これを解決するには?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="4" 
    android:background="@drawable/bg"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="10dp" 
     android:weightSum="3" > 

     <Button 
      android:id="@+id/loadmoney" 
      android:text="Load\nMoney" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" 
      android:drawableTop="@android:drawable/ic_menu_edit"/> 

     <Button 
      android:id="@+id/requestmoney" 
      android:text="Request\nMoney" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" /> 

     <Button 
      android:id="@+id/sendmoney" 
      android:text="Send\nMoney" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:weightSum="3" > 

     <Button 
      android:id="@+id/recharge" 
      android:text="Recharge" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" /> 

     <Button 
      android:id="@+id/paybill" 
      android:text="Pay Bill" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" /> 

     <Button 
      android:id="@+id/checkbalance" 
      android:text="Check\nBalance" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:weightSum="3" > 

     <Button 
      android:id="@+id/cashout" 
      android:text="CAsh Out" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" /> 

     <Button 
      android:id="@+id/paymerchant" 
      android:text="Pay\nMerchant" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" /> 

     <Button 
      android:id="@+id/viewtransaction" 
      android:text="View\nTransaction" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginBottom="10dp" 
     android:weightSum="3" > 

     <Button 
      android:id="@+id/loan" 
      android:text="Loan" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" /> 

     <Button 
      android:id="@+id/insurance" 
      android:text="Insurance" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" /> 

     <Button 
      android:id="@+id/kyc" 
      android:text="Know Your\nCustomer" 
      android:textColor="#FFFFFF" 
      android:textSize="10sp" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@drawable/dashboard_button" /> 

    </LinearLayout> 

</LinearLayout> 

このコードは、正確な円形のビューを示します。しかし、それは圧縮されますし、あなたのscreenHeightない限り

+0

循環描画可能https://stackoverflow.com/questions/10266595/how-to-make-a-round-buttonを作成しようとし、グリッド表示を使用する代わりにボタンを使用 – Akshay

答えて

0

あなたのコードによると、ボタンの幅= screenWidth/4、高さ= screenHeight/4

を実行した後に電話で見たときに円形のボタンの大きさが乱さ取得しますscreenHeightと等しくなります。そうでなければ、間違いなく圧縮されます。

+0

ボタンのプロパティを動的に変更することができますあなたの活動。 – Deng

+0

int screenWidth = getWindowManager()。getDefaultDisplay()。getWidth();int screenHeight = getWindowManager()。getDefaultDisplay()。getHeight(); screenWidth = screenWidth Deng

関連する問題