Issue
Is it possible to show multiple drawables (with margins in between them) inside an ImageView without using a frame layout + any unnecessary nesting? How can following be achieved?
- Each drawable to appear as normal without any resizing
- Only
drawableA
anddrawableB
to have 10dp margin on the end/right
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(?);
Solution
An ImageView
only houses a single Drawable
. Multiple ImageViews
are needed to display multiple Drawable
s.
You could replace the root LinearLayout
with a RelativeLayout
to avoid nesting.
Answered By - aruh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.