導航:首頁 > 操作系統 > androidclipdrawable

androidclipdrawable

發布時間:2025-07-21 07:43:37

android裡面layer-list中的inset和clip到底有什麼作用

Inset Drawable:用於通過指定的間距把圖片插入到XML中,它在View需要比自身小的背景時常用。有些像padding的作用。例子:
第一步:drawable文件中建立inset_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<inset
xmlns:android="http://schemas。android。com/apk/res/android"
android:drawable="@drawable/photo2"
android:insetTop="100dp"
android:insetRight="100dp"
android:insetBottom="200dp"
android:insetLeft="100dp" />

第二部,在xml中引用
<LinearLayout xmlns:android="http://schemas。android。com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/inset_drawable">

Clip Drawable:可以剪載圖片顯示,例如,可以通過它來做進度度。你可以選擇是從水平或垂直方向剪載。其中的gravity設置從整個部件的哪裡開始。例子:
第一步,在drawable文件中建立:clip_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas。android。com/apk/res/android"
android:drawable="@drawable/test_img"
android:clipOrientation="horizontal"
android:gravity="left" />
第二步,在ImageView中引用:
<LinearLayout xmlns:android="http://schemas。android。com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:id="@+id/clipimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/clip_drawable"/>
</LinearLayout>
Dev Guide中在ImageView中設置的是android:background="@drawable/clip_drawable",但是我使用background的時,會在程序中報空指針的錯誤。
最後,使用程序控制:
ImageView imageView=(ImageView)findViewById(R.id.clipimage);
ClipDrawable clipDrawable=(ClipDrawable)imageView.getDrawable();
clipDrawable.setLevel(5000);
level的值為0到10000 。當值為10000時圖全部顯示。

閱讀全文

與androidclipdrawable相關的資料

熱點內容
滴滴程序員平均月薪 瀏覽:588
如何使用ftp命令 瀏覽:785
小書亭下載的文件在哪手機文件夾 瀏覽:173
交叉編譯器編譯單個c文件 瀏覽:509
代理伺服器地址列表吧 瀏覽:928
java列出所有文件 瀏覽:866
壓縮包看圖軟體 瀏覽:187
sqlite在android中的應用 瀏覽:658
一本通pdf 瀏覽:913
2021免費的編程軟體 瀏覽:124
項目編譯後瀏覽器不對應刷新 瀏覽:565
三星升級android60 瀏覽:295
粘土的壓縮模量 瀏覽:118
美國程序員生活 瀏覽:222
51單片機摘要 瀏覽:408
英語經典pdf下載 瀏覽:320
大學文件夾怎麼刪除 瀏覽:671
linux科研軟體 瀏覽:556
ue4打包編譯著色器 瀏覽:778
雲伺服器可以在手機上登錄嗎 瀏覽:678