2012-02-16 17 views
0

私は垂直LinearLayoutandroid:layout_height = "fill_parent"を持っています。垂直線形レイアウトで子ビューを比例配分する

これで、データベースからの特定のパラメータに基づいて、複数の子ビューを追加し、時には2つのビューを追加しました。

私はこれらの動的に追加された子ビューを垂直方向にプログラムで配布することができます。LinearLayoutは一様に分散されるようにします。

ところで、私は、水平ScrollViewでこのLinearLayoutを埋め込むために持っているようにGridViewを使用し、水平ScrollViewGridViewを使用することを強く推奨されないことができます。

EDIT:追加ソースとxmlファイル:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/serverScreensScreen1LL1" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#FFFFFF" > 

<ScrollView 
     android:id="@+id/serverScreensScreen1SV1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" 
     > 

    <HorizontalScrollView 
     android:id="@+id/serverScreensScreen1HSV1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" 
     > 

     <LinearLayout 
      android:orientation="horizontal" 
      android:id="@+id/serverScreensScreen1LL2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

     </LinearLayout> 
    </HorizontalScrollView> 
</ScrollView> 
</LinearLayout> <!-- Main Container --> 

SOURCE:

private void drawContent() 
{ 
    LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(fpfp); 

    LinearLayout.LayoutParams lp3 = new LinearLayout.LayoutParams(wcwc); 
    lp3.weight = 0.3F; 

    LinearLayout ll1 = (LinearLayout) findViewById(R.id.serverScreensScreen1LL2); 

    for (int i=0; i<20; i++) 
    { 
      LinearLayout ll2 = new LinearLayout(this); 
      ll2.setOrientation(LinearLayout.VERTICAL); 
      ll2.setLayoutParams(new   LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,  LinearLayout.LayoutParams.FILL_PARENT)); 
      ll2.setWeightSum(1.0F); 

       LinearLayout ll3 = new LinearLayout(this); 
       ll3.setOrientation(LinearLayout.VERTICAL); 
       ll3.setLayoutParams(lp3); 
        TextView tv1 = new TextView(mContext); 
        tv1.setText("Sample Text A: " + i); 
        tv1.setBackgroundColor(Color.rgb(12, 34, 56 + i * 8)); 
        tv1.setLayoutParams(wcwc); 
       ll3.addView(tv1); 


       LinearLayout ll4 = new LinearLayout(this); 
       ll4.setOrientation(LinearLayout.VERTICAL); 
       ll4.setLayoutParams(lp3); 
        TextView tv2 = new TextView(mContext); 
        tv2.setText("Sample Text B: " + i); 
        tv2.setBackgroundColor(Color.rgb(34, 12 + i * 8, 56)); 
        tv2.setLayoutParams(wcwc); 
       ll4.addView(tv2); 

       LinearLayout ll5 = new LinearLayout(this); 
       ll5.setOrientation(LinearLayout.VERTICAL); 
       ll5.setLayoutParams(lp3);    
        TextView tv3 = new TextView(mContext); 
        tv3.setText("Sample Text C: " + i); 
        tv3.setBackgroundColor(Color.rgb(56 + i * 8, 34, 12)); 
        tv3.setLayoutParams(wcwc); 
       ll5.addView(tv3); 

      ll2.addView(ll3); 
      ll2.addView(ll4); 
      ll2.addView(ll5); 

     ll1.addView(ll2); 
    } 
} 

任意の提案plzは...

+0

それぞれの子供には、アンドロイド:layout_weight = "1" – Booger

+0

を設定しました。... –

+0

Nitin Bansal、もう一度試してくださいlayout_weight - あなたの必要とするものです – Silver

答えて

0

私はあなたが配布しようとしているかを確認していませんあなたはウェイトで遊ぶことができます。

のドキュメント内でandroid:weightSumを検索してください。

+0

私はソースファイルで質問を更新しました。何かが不足しているかどうかを確認してください... thnx in advance ... –

+0

@NitinBansal:あなたが試みているもののイメージを描画するか作成できますか?達成するために? 'Horizo​​ntalScrollView'を内部に持つ' ScrollView'を持っているのはうまくありません。 – Macarse

+0

@Sure ...ここに私が望むバットの描画があります:http://twitpic.com/8kor38 .... btw、私スクロールビュー内にすべてのものを埋め込んで、多くの行が必要な場合を考慮して、より可視的な領域を占有します。より良い選択肢、私に教えてください。私もこのことに賛成ではない –

関連する問題