2016-09-16 6 views
-1

私は3行に9つのボタンがあり、FrameLayoutも必要です。その目的は、ユーザーがメニューオプションをクリックして何かを選択したときにボタンを削除し、FrameLayoutを開くことです。 enter image description hereボタンでレイアウトにframelayoutを配置するにはどうすればいいですか?

そして、これのようなとき、私それがどのように見えるかです:私はこれは私がFrameLayoutを入れしようとすると何が起こるかであるFrameLayout を置くしようとすると、奇妙なことが起こると私は何のために助けを必要とすることは、このレイアウトのXMLですそれを持っていない:ここでは

enter image description here

は、レイアウトのための私のXMLです:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="#32c6a6" 
       android:weightSum="3"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="3"> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:minWidth="25px" 
      android:minHeight="25px" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/linRow1" 
      android:layout_weight="1" 
      android:weightSum="3"> 
      <Button 
       android:text="13 egenskaber" 
       android:id="@+id/G_Egenskaber" 
       android:textSize="15dp" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/redbotton" 
       android:layout_weight="1" 
       android:textColor="#ffffff"/> 
      <Button 
       android:text="Profeternes egenskaber" 
       android:id="@+id/P_egenskaber" 
       android:textSize="15dp" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/redbotton" 
       android:layout_weight="1" 
       android:textColor="#ffffff"/> 
      <Button 
       android:text="Bøntider" 
       android:id="@+id/Boentider" 
       android:textSize="15dp" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/redbotton" 
       android:layout_weight="1" 
       android:textColor="#ffffff"/> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:minWidth="25px" 
      android:minHeight="25px" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/linRow2" 
      android:layout_weight="1" 
      android:weightSum="3"> 
      <Button 
       style="?android:attr/buttonStyleSmall" 
       android:text="Wudu" 
       android:id="@+id/Wudu" 
       android:textSize="15dp" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/bluebotton" 
       android:layout_weight="1" 
       android:textColor="#ffffff"/> 

      <Button 
       android:text="Wudu's betingelser" 
       android:id="@+id/Wudu_B" 
       android:textSize="15dp" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/bluebotton" 
       android:layout_weight="1" 
       android:textColor="#ffffff"/> 
      <Button 
       style="?android:attr/buttonStyleSmall" 
       android:text="Wudu's afbrydelser" 
       android:id="@+id/Wudu_A" 
       android:textSize="15dp" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/bluebotton" 
       android:layout_weight="1" 
       android:textColor="#ffffff"/> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:minWidth="25px" 
      android:minHeight="25px" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/linRow3" 
      android:layout_weight="1" 
      android:weightSum="3"> 
      <Button 
       android:text="Bønnens søjler" 
       android:id="@+id/Boen_S" 
       android:textSize="15dp" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/yellowbotton" 
       android:layout_weight="1" 
       android:textColor="#ffffff"/> 
      <Button 
       android:text="Bønnens betingelser" 
       android:id="@+id/Boen_B" 
       android:textSize="15dp" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/yellowbotton" 
       android:layout_weight="1" 
       android:textColor="#ffffff"/> 
      <Button 
       android:text="Bønnens afbrydelser" 
       android:id="@+id/Boen_A" 
       android:textSize="15dp" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/yellowbotton" 
       android:layout_weight="1" 
       android:textColor="#ffffff"/> 
     </LinearLayout> 
    </FrameLayout> 


</LinearLayout> 
+0

ボタンで2つのレイアウト - xmlを作成し、フレームレイアウトで1つを作成し、インフレータでロードすることができます – Flo

答えて

0

あなたは線形レイアウトを持っていますinside framelayout。親ではないピアである必要があります。

Javaコードで次に
<?xml version="1.0" encoding="utf-8"?> 

<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/switcher" 
    android:layout_weight="0" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <FrameLayout 
     android:id="@+id/frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <LinearLayout 
     android:id="@+id/buttons" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#32c6a6"> 

    <LinearLayout 

     android:orientation="horizontal" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/linRow1" 
     android:layout_weight="1" 
     android:weightSum="3"> 
     <Button 
      android:text="13 egenskaber" 
      android:id="@+id/G_Egenskaber" 
      android:textSize="15dp" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/redbotton" 
      android:layout_weight="1" 
      android:textColor="#ffffff"/> 
     <Button 
      android:text="Profeternes egenskaber" 
      android:id="@+id/P_egenskaber" 
      android:textSize="15dp" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/redbotton" 
      android:layout_weight="1" 
      android:textColor="#ffffff"/> 
     <Button 
      android:text="Bøntider" 
      android:id="@+id/Boentider" 
      android:textSize="15dp" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/redbotton" 
      android:layout_weight="1" 
      android:textColor="#ffffff"/> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/linRow2" 
     android:layout_weight="1" 
     android:weightSum="3"> 
     <Button 
      style="?android:attr/buttonStyleSmall" 
      android:text="Wudu" 
      android:id="@+id/Wudu" 
      android:textSize="15dp" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/bluebotton" 
      android:layout_weight="1" 
      android:textColor="#ffffff"/> 

     <Button 
      android:text="Wudu's betingelser" 
      android:id="@+id/Wudu_B" 
      android:textSize="15dp" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/bluebotton" 
      android:layout_weight="1" 
      android:textColor="#ffffff"/> 
     <Button 
      style="?android:attr/buttonStyleSmall" 
      android:text="Wudu's afbrydelser" 
      android:id="@+id/Wudu_A" 
      android:textSize="15dp" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/bluebotton" 
      android:layout_weight="1" 
      android:textColor="#ffffff"/> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/linRow3" 
     android:layout_weight="1" 
     android:weightSum="3"> 
     <Button 
      android:text="Bønnens søjler" 
      android:id="@+id/Boen_S" 
      android:textSize="15dp" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/yellowbotton" 
      android:layout_weight="1" 
      android:textColor="#ffffff"/> 
     <Button 
      android:text="Bønnens betingelser" 
      android:id="@+id/Boen_B" 
      android:textSize="15dp" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/yellowbotton" 
      android:layout_weight="1" 
      android:textColor="#ffffff"/> 
     <Button 
      android:text="Bønnens afbrydelser" 
      android:id="@+id/Boen_A" 
      android:textSize="15dp" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/yellowbotton" 
      android:layout_weight="1" 
      android:textColor="#ffffff"/> 
    </LinearLayout> 

    </LinearLayout> 
</ViewSwitcher> 

viewSwitcher.setDisplayedChild (0); 

のLinearLayoutを表示するには、フレームのレイアウトと

viewSwitcher.setDisplayedChild (1); 

を表示します。

+0

今は黄色の代わりに赤いボタンが表示されます –

+0

@dadadudu間違いとあなたのためのより良い解決策の考え。 –

+0

GridLayoutはもう一つの選択肢かもしれません –

関連する問題