[英]How to set the height of a programatically created ImageView inside of a TableRow inside of a TableLayout?
[英]How to display multiple drawables (with margins) inside ImageView programatically
是否可以在ImageView中显示多个可绘制对象(它们之间有边距),而无需使用框架布局和任何不必要的嵌套? 如何实现跟进?
drawableA
和drawableB
的末端/右边有10dp的边距 XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/myImgView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/myTxtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Java的
Resources r = getContext().getResources();
int tenDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, r.getDisplayMetrics());
ImageView customIV = content.findViewById(R.id.myImgView);
Drawable drawableA = getResources().getDrawable(R.drawable.ic_happyface);
Drawable drawableB = getResources().getDrawable(R.drawable.ic_neutralface);
Drawable drawableC = getResources().getDrawable(R.drawable.ic_sadface);
customIV.addView(?);
ImageView
仅包含一个Drawable
。 需要多个ImageViews
才能显示多个Drawable
。
您可以用RelativeLayout
替换根目录LinearLayout
以避免嵌套。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.