任何人都可以幫助我解決這個問題。如何以編程方式在線性佈局中的圖像下添加textview?
我想在線性佈局下在我的圖像下添加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>
我想在圖像下方添加文字。 – Joehamir