2017-01-26 5 views
0

enter image description hereはどのように私は、水平直線レイアウト方向内側textviewsを管理する

コード:あなたはあなたのレイアウトxmlファイルを投稿することができます

LinearLayout linearLayout2; 

final JSONArray answer=jsonObject1.getJSONArray("answer"); 
//Here get Answer from question 

    ((ViewGroup) findViewById(R.id.linearLayout2)).removeView(linearLayout2);     //Here remove preselected radiobuttons 
    linearLayout2 = new LinearLayout(TestActivity2.this);          //Here create new viewgroup when user click next and previous 
    linearLayout2.setOrientation(LinearLayout.HORIZONTAL); 
    linearLayout2.setGravity(Gravity.FILL_HORIZONTAL); 

    indexAns=new String[answer.length()]; 

    for(int j=0;j<answer.length();j++) 
    { 
     final JSONObject jsonObject2 = answer.getJSONObject(j); 
     final String answer_ans=jsonObject2.getString("answer_ans");       //get answer from loop 

     answer_id=jsonObject2.getString("answer_id"); 

     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 
       LinearLayout.LayoutParams.WRAP_CONTENT); 

     //Here create radio buttons depending on answer loop 
     final TextView textBtn = new TextView(TestActivity2.this); 
     textBtn.setId(Integer.parseInt(answer_id)); 
     textBtn.setLayoutParams(params); 
     textBtn.setAllCaps(true); 
     textBtn.setTextSize(12); 
     textBtn.setPadding(5,5,5,5); 
     textBtn.setGravity(Gravity.LEFT | Gravity.CENTER |Gravity.RIGHT); 
     textBtn.setTextColor(Color.parseColor("#000000")); 

     indexAns[j]=answer_id; 
+4

ようこそ。あなたの質問は何ですか? – Shashanth

+1

@Abhishekはあなたのコードをあなたのコードに書いておきます。問題を解決するために、私たちが手助けをしています。 –

答えて

0

。あなたはプログラムでレイアウトを操作しているように見えますが、ほとんどの場合は不要です。 xmlレイアウトファイルを使用して同じ目標を達成できます。

また、書式設定にスタイルを使用すると、時間を大幅に節約できます。

次のレイアウトのドキュメントをチェックアウト https://developer.android.com/guide/topics/ui/declaring-layout.html

のTextViewのドキュメントチェックアウト:StackOverflowのに https://developer.android.com/reference/android/widget/TextView.html

関連する問題