Reputation: 2119
I am try to set image background . I am creating a View that's background color is red .
All view and set image background programmatically .
this is my code
final View trans_View = new ImageView(MyClass.this);
ImageView img = (ImageView)findViewById(R.id.img);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
100, 100);
params.setMargins(10, 2, 10, 2);
trans_View.setBackgroundColor(Color.RED);
trans_View.setLayoutParams(params);
img.setBackground View ????
example-
Actual image :
when i select Image then display below output.
I don't know how to set view as image background .
Please help me...
Upvotes: 0
Views: 159
Reputation: 23982
It is not possible.
If you just need to add background to your ImageView
use setBackgroundColor(Color.RED)
.
Or if you're really need to use View
as a background, you can use FrameLayout
:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:layout_width="100dp"
android:layout_height="100dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="100dp" />
</FrameLayout>
However this is not recomended, since there will be unneccecary overdraw.
Upvotes: 1