android中layout的背景

android中对layout设置背景可以有“静态“和“动态“两种方式。

所谓“静态“,指的是在layout的xml文件中指定,如:

<com.intel.camera22.ui.RotateImageView
                android:id="@+id/shortcut_mode_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"

                android:src="@drawble/image1 />

这种方式,当layout inflate的同时,设置layout的背景。

所谓“动态“,指在代码中指定layout的背景,如:

<com.intel.camera22.ShutterButton
                        android:id="@+id/shutter_button"
                        android:layout_width="198dp"
                        android:layout_height="198dp"
                        android:clickable="true"
                        android:contentDescription="@string/accessibility_shutter_button"
                        android:focusable="true"
                        android:padding="10dp"
                        android:layout_gravity="center" />

此处没有指定image src。在java代码中,可以作如下设置:

mShutterButton = (ShutterButton) findViewById(R.id.shutter_button);
        mShutterButton.setImageResource(R.drawable.btn_shutter);


注意,有些场合是不适合用“静态“设置的方式的,否则在场景切换的过程中,将有可能看到一些预期设计中所没有的“额外的“UI:这些都是因为在xml文件中指定了背景图片的原因。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值