2016-05-18 4 views
-1

下記の画像のように、アンドロイドでフォームを作成しようとしています。どのような形でこのタイプのフォームを作成するのが最善のアプローチですか。アンドロイドのXMLデザインでこのタイプのフォームを実現するにはどうすればいいですか?コンポーネントは動的コンポーネントではありません。私はすべての動的コンポーネントを追加する必要があります。Androidの条件xmlデザインに基づくテキストの異なるコンポーネント

フィールドで検証を実行する必要があるかもしれません。

enter image description here

+0

「縦方向」の向きで「線形レイアウト」を使用します。 –

+0

はい、重力と重量の概念を使用して線形レイアウトを使用する必要があります –

+0

どのようにコンポーネントを追加できますか?それらは動的な静的なコンポーネントではありません。 –

答えて

0

使用GridLayoutにこのタイプのレイアウトを実現しています。あなたは自分の願いとしてテキストを与えることができます。 EXのために

<?xml version="1.0" encoding="utf-8"?> 
<GridLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:columnCount="4" 
    android:rowCount="4" > 

    <TextView 
     android:text="1,1" /> 

    <TextView 
     android:text="1,2" /> 

    <TextView 
     android:text="1,3" /> 

    <TextView 
     android:text="1,4" /> 

    <TextView 
     android:text="2,1" /> 

    <TextView 
     android:text="2,2" /> 

    <TextView 
     android:text="2,3" /> 

    <TextView 
     android:text="2,4" /> 

    <TextView 
     android:text="3,1" /> 

    <TextView 
     android:text="3,2" /> 

    <TextView 
     android:text="3,3 longer" /> 

    <TextView 
     android:text="3,4" /> 

    <TextView 
     android:text="4,1" /> 

    <TextView 
     android:text="4,2" /> 

    <TextView 
     android:text="4,3" /> 

    <TextView 
     android:text="4,4" /> 

</GridLayout> 

enter image description here

+0

行数と列数は私のフォームで動的になります。 –

+0

シンプルで、プログラムでテキストビューを作成し、そのビューをgridlayoutに追加します。 –

0

はまず、あなたは、その子としてのLinearLayoutとスクロールビューを取るmLinearLayoutを言うそれにIDを与える必要があります。そのidを使用すると、そのレイアウトにn個のビューを追加できます。 、プログラムでリニアレイアウトにレイアウトを追加するには、リニアレイアウトにプログラムでビューを追加するために、今すぐ

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/mLinearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

    </LinearLayout> 
</ScrollView> 

をとっていると仮定する

サンプル方法、そして、あなたはリニアレイアウトにのTextViewを追加したいと言います

TextView textView = new TextView(this); 
textView.setText("Hello World!"); 
textView.setId(5); 
textView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); 
mLinearLayout.addView(textView); 
+0

同じ行にedittextとradioチェックボックスを使ってテキストビューを追加する方法を教えてください。 –

関連する問題