2017-07-04 77 views
-1

我試圖創建一個應用程序,將在一行中有4個方形按鈕與這些按鈕上的圖標。哪種方法是最好的方法?我想,如下圖所示Android-如何在一行上創建4個方形按鈕,並在上面放置圖標?

enter image description here

謝謝

+0

沒有最好的辦法。你試過什麼了?究竟是什麼問題?使按鈕成方形?把它們放在一排?在他們上面放置圖標? –

+0

我的2分錢投入:一個GridView與一行ImageButtons。 –

+0

你可以使用Weight來平均分配其中的4個行。你可以發佈你的Code.What你有做到目前爲止?? – seon

回答

0

上進行@紋理貼圖/ ic_launcher_round

<?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"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="4sp" 
     android:orientation="horizontal" 
     android:weightSum="4"> 


     <ImageButton 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="4sp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher_round" /> 

     <ImageButton 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="4sp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher_round" /> 

     <ImageButton 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="4sp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher_round" /> 

     <ImageButton 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="4sp" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher_round" /> 


    </LinearLayout> 

</LinearLayout> 
0

您是否嘗試過表佈局中做這樣的事情?雖然您可以使用任何佈局,但我建議您堅持一個父佈局,如相對佈局,然後再使用多個子佈局來管理UI元素。

+0

我建議不要使用「兒童佈局」,因爲嵌套佈局不利於演出。 –

+0

是的。但有時候,當你不想使用約束佈局時,你必須使用這種方法。 – Abhinash

+0

或者您可以使用GridView,就像我之前評論中所建議的那樣。 –

相關問題