2016-04-03 13 views
0

を記入し、それがコードだ次のとおりです。は動的</p> <p><a href="http://i.stack.imgur.com/0khRU.jpg" rel="nofollow">Click for screenshot</a></p> <p>..ので、私はこのように見えるの相対レイアウトを持って事前に定義された相対的なレイアウト

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/imageView" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:src="@drawable/image" 
      android:scaleType="fitXY" /> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="New Button" 
      android:id="@+id/button" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" 
      android:background="#60000000" 
      android:textSize="30dp" 
      android:textAlignment="textEnd" 
      android:textColor="#ffffff" /> 

    </RelativeLayout> 

私は2つのものを持っています最初にこの相対レイアウトを繰り返し動的に使用し、イメージビューとテキストビューに異なるコンテンツを埋めます。

第2に、Relativelayoutを動的に並べ替えることをお勧めします。 like this練習は必要性のこの種のRecyclerViewを使用しているベスト

+0

使用 'RecyclerView'のような類似した表情に –

答えて

0
+0

おかげでたくさん...ところで、動的にそれらを次々に配置する方法を持っているあなたの子のレイアウトに属性を適用することができます... !! :) –

+0

レイアウトマネージャをそのリサイクラビュー用のリニアレイアウトマネージャとして設定する必要があります。リサイクルビューのドキュメントとチュートリアルを参照してください。リニアーワンは、recyclerView.setLayoutManger(new LinearLayoutManager(context) – erluxman

0

からそれらを学ぶことができます。しかし、それでもを膨張させてを膨張させ、このレイアウトを親レイアウトに追加する必要があります。

public class Item { 
    private String text; 
    private int background; 

    public Item (String text_, int background_) { 
     this.text = text_; 
     this.background = background_; 
    } 

    public String getText() { return this.text; } 

    public int getBackground() { return this.background; } 
} 

は、あなたがこのオブジェクトのArrayList<Item>を持っているとしましょうあなたが背景とテキストが含まれているモデルを持っている想像してみてください。親線形レイアウトがあります。

LinearLayout parentLayout = (LinearLayout)findViewById(R.id.parent_layout); 
for (Item item: items) { 
     View view = getLayoutInflater(null).inflate(R.layout.your_button_layout, parentLayout, false); 
     TextView text= (TextView) view.findViewById(R.id.text); 
     ImageView background= (ImageView) view.findViewById(R.id.image); 
     text.setText(item.getText()); 
     background.setBackground(item.getBackground()); 

     parentLayout.addView(view); 
    } 

あなたは余裕&パディングがRecyclerView

関連する問題