2017-08-03 56 views
2

この質問はhereでしたが、私はまだ間違っていることが分かりません。 Logcatにエラーはなく、そこにデータが渡されていることは間違いありません。ここに私のセットアップがあります:動的に作成されたレイアウトが表示されない

これは私がAndroidスタジオに配置した手動で配置された要素の下で行われます。私はScrollViewを持っています。そのScrollViewの内部には、LinearLayout、parentLayoutがあり、このクラスに渡されます。このメソッドは、別のHorizo​​ntal LinearLayout、layout,parentLayoutを追加することになっています。次に、TextView、titleDisplay、および2つのボタンをlayoutに追加することになっています。今のところ、私はちょうどlayouttitleDisplayをプログラムしました。私はそれをテストし、何も追加されませんでした。だから私が他の2つのボタンをプログラムする前に、私が間違っていることを知りたい。ここではJavaコードだ:

public class FollowupOption { 

private String displayName; 
private JSONObject jsonInformation; 
private Context context; 
private LinearLayout parentLayout; 

private LinearLayout layout; 
private TextView titleDisplay; 
private Button deleteButton, editButton; 

public FollowupOption(String displayName, JSONObject jsonInformation, 
         Context context, LinearLayout parentLayout){ 
    this.displayName = displayName; 
    this.jsonInformation = jsonInformation; 
    this.context = context; 
    this.parentLayout = parentLayout; 
    buildLayout(); 
} 

private void buildLayout(){ 
    //Horizontal Linear Layout to hold everything 
    this.layout = new LinearLayout(context); 
    this.layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 
    this.layout.setOrientation(LinearLayout.HORIZONTAL); 
    this.parentLayout.addView(this.layout); 
    //Text View Displaying title of followup option. 
    this.titleDisplay = new TextView(context); 
    try { 
     this.titleDisplay.setText(this.jsonInformation.getJSONObject("list").getString("title")); 
    } catch(JSONException e){ e.printStackTrace(); } 
    this.titleDisplay.setTextColor(0x8f142a); //Black 
    this.titleDisplay.setTextSize(18); 
    this.titleDisplay.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); 
    this.layout.addView(this.titleDisplay); 
} 
} 

ここに私のXMLです:

<?xml version="1.0" encoding="utf-8"?> 
<merge xmlns:android="http://schemas.android.com/apk/res/android"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/parent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:paddingTop="10dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="38dp" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/textView15" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="0.22" 
       android:gravity="center" 
       android:text="@string/followup_text" 
       android:textColor="@color/myRed" 
       android:textSize="18sp" /> 

      <Button 
       android:id="@+id/followup_add_button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@android:color/transparent" 
       android:text="@string/plus" 
       android:textAlignment="center" 
       android:textColor="@android:color/holo_green_dark" 
       android:textSize="30sp" 
       android:textStyle="bold" /> 
     </LinearLayout> 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="279dp" 
      android:paddingLeft="7dp" 
      android:paddingRight="7dp" 
      android:paddingTop="7dp"> 

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

      </LinearLayout> 
     </ScrollView> 

     <Button 
      android:id="@+id/followup_new_button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/new_followup_text" /> 
    </LinearLayout> 
</merge> 

誰かが私は私が間違っているのか知ってみましょうか、高く評価されるだろう。このような何かを、デバッグするための良い方法ができれば。

+0

XMLがレイアウトの問題ではないことを確認するのに役立ちます – Milk

+0

XML @Milkで質問を更新しました – SH7890

+0

スタックトレースが表示されていますか? 'this.titleDisplay.setText(...)'をいくつかの静的テキストに置き換えることはできますか? – Milk

答えて

1

いくつかのビューにthis.layoutビューを追加していますか?

UPD:問題はテキストの色にあります。 Colorクラスを使用して、そのクラスの16進値または定数から色を取得することを検討してください。

+0

この行は 'this.parentLayout.addView(this.layout);'それを行いませんか? – SH7890

+0

'this.parentLayout'とは何ですか?私は 'parentLayout'がビューに追加されていないかもしれません。 – Milk

+1

そうです。あなたはこのクラスの完全なコードを提供できますか?これがなぜ機能しないのか分かりません。 –

0

XMLビュー(動的レイアウトを追加しない)が画面全体を占めていますか?

新しいLinearLayoutビューがボタンの下に追加されます。ボタンが画面の最下部にある場合、レイアウトは画面外に追加されるため、表示されません。

新しいレイアウトをスクロールビューに追加する必要があります。

+0

私は、画面の中央でスクロールビューにビューを追加しています。 –

+0

まあ、私は、新しいLinearLayoutが 'parentLayout'(xmlのfollowup_parent)に追加されると考えました。 ScrollViewに追加することをお勧めします。 – SH7890

+0

まだ何も表示されていません。 – SH7890

関連する問題