2016-03-29 7 views
0

誰でもこの問題を助けることができます。どのようにして、画像の下にリニアレイアウトのプログラムでテキストビューを追加できますか?

私はリニアレイアウトで画像の下にtextviewを追加したいと思います。

Javaクラスのコードを使用しています。ここ

は私のコードコードの下

for (int ir = 0; ir < jsonarrayProductsRecent.length(); ir++) { 
    HashMap<String, String> map = new HashMap<String, String>(); 
    JSONObject pr = jsonarrayProductsRecent.getJSONObject(ir); 

    ImageView thumbView = new ImageView(getActivity()); 
    Display display = getActivity().getWindowManager().getDefaultDisplay(); 
    int width = ((display.getWidth()*50)/100); // ((display.getWidth()*20)/100) 
    int height = display.getHeight();// ((display.getHeight()*30)/100) 
    LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(width,LinearLayout.LayoutParams.WRAP_CONTENT); 
    //LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(width,height); 
    thumbView.setLayoutParams(parms); 
    thumbView.setAdjustViewBounds(true); 
    thumbView.setPadding(0, 0, 10, 0); 
    Glide.with(getActivity()) 
      .load(pr.getString("products_image")).diskCacheStrategy(DiskCacheStrategy.ALL) 
      .into(thumbView); 
    TextView tv= new TextView(getActivity()); 
    tv.setText("XYZ"); 
    layout.addView(thumbView); 
    layout.addView(tv); 

} 

である私のxmlレイアウト

<HorizontalScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="horizontal" 
    android:id="@+id/horizontalScrollView" 
    android:fillViewport="false"> 

    <LinearLayout 
     android:id="@+id/linear" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"/> 


</HorizontalScrollView> 
+0

私は画像の下にテキストを追加したいと思います。 – Joehamir

答えて

0

はこの

for (int ir = 0; ir < jsonarrayProductsRecent.length(); ir++) { 
HashMap<String, String> map = new HashMap<String, String>(); 
JSONObject pr = jsonarrayProductsRecent.getJSONObject(ir); 

ImageView thumbView = new ImageView(getActivity()); 
Display display = getActivity().getWindowManager().getDefaultDisplay(); 
int width = ((display.getWidth()*50)/100); // ((display.getWidth()*20)/100) 
int height = display.getHeight();// ((display.getHeight()*30)/100) 
LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(width,LinearLayout.LayoutParams.WRAP_CONTENT); 
thumbView.setLayoutParams(parms); 
thumbView.setAdjustViewBounds(true); 
thumbView.setPadding(0, 0, 10, 0); 
Glide.with(getActivity()) 
     .load(pr.getString("products_image")).diskCacheStrategy(DiskCacheStrategy.ALL) 
     .into(thumbView); 
llImage.addView(thumbView);  
TextView tv= new TextView(getActivity()); 
tv.setText("XYZ"); 
LinearLayout.LayoutParams captionViewlayoutParams = new LinearLayout.LayoutParams(
        width, height); 
tv.setLayoutParams(captionViewlayoutParams); 
llCaption.addView(tv); 
} 

and change Your xml to this 

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

       <LinearLayout 
        android:id="@+id/llImage" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" > 
       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/llCaption" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:gravity="center" 
        android:orientation="horizontal" > 
       </LinearLayout> 
      </LinearLayout> 
       </HorizontalScrollView> 
+0

私は下のテキストをイメージします。 – Joehamir

+0

このコードは、最初に 'thumbView'を追加し、' tv'の後に ' –

+0

が残っています。私のコードが間違っています。編集を参照してください。私のコードはforループです。 – Joehamir

0

があなたのコードに次の行を追加してみている:

layout.setOrientation(LinearLayout.VERTICAL); 
関連する問題