如何在android中将视图设置为图像背景?
我正在尝试设置图像背景。我正在创建一个背景色为红色的视图 全部以编程方式查看和设置图像背景 这是我的密码如何在android中将视图设置为图像背景?,android,Android,我正在尝试设置图像背景。我正在创建一个背景色为红色的视图 全部以编程方式查看和设置图像背景 这是我的密码 final View trans_View = new ImageView(MyClass.this); ImageView img = (ImageView)findViewById(R.id.img); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
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视图???
范例-
实际图像:
当我选择图像,然后显示下面的输出
我不知道如何将视图设置为图像背景
请帮帮我…这是不可能的
如果您只需要将背景添加到ImageView
中,请使用setBackgroundColor(Color.RED)
或者,如果您确实需要使用查看作为背景,您可以使用框架布局:
<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>
但是,不建议这样做,因为会出现不必要的透支