vov*_*ost 10 android android-layout android-drawable
如Android Developer网站所述:
以XML格式定义的drawable,它将另一个drawable以指定的距离进行插入.当View需要的背景小于View的实际边界时,这非常有用.
http://developer.android.com/guide/topics/resources/drawable-resource.html#Inset
在我的情况下,插入不仅仅是移动背景并将内容留在原位,而是移动TextView.
这是布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_inset"
android:orientation="horizontal" >
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some text"
android:textSize="23sp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是bg_inset drawable
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@android:color/darker_gray"
android:insetLeft="100dp" />
Run Code Online (Sandbox Code Playgroud)
这是我得到的结果:

j__*_*__m 14
默认情况下,设置背景可绘制也会将该drawable的填充应用于视图.如果您不希望它与背景可绘制匹配,请显式设置填充.
| 归档时间: |
|
| 查看次数: |
6948 次 |
| 最近记录: |