616
技術社區[雲棲]
手機衛士04-自定義顯示圖片
首先,先和大家說個對不起先,昨天太趕啦,一時沒說清楚昨天的內容,其實昨天還有一些UI的知識點還沒講的,而且那個代碼也是有一點問題的,所以今天把它補回來
我們先講一下,昨天忘記說了的內容
其實昨天忘記說了的就是那個自定義標題欄那裏啦
自定義標題欄,其實就是把原來的標題欄隱藏掉,然後再自己寫一個TextView這些的控件,把它放上去的而已,一說就很簡單的啦
但我們這裏有一個知識點的
那就是自定義圖片,其實上麵的那個手機防盜這些文字外麵的那個框,就是用到啦自定義圖片的啦
要自定義圖片,也很簡單,我們要先在drawable的目錄下麵,新建一個xml文件
下麵是我自己建的那個文字的背景text_background.xml
- <font color="#333333"><font face="Arial"><?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:andro
- android:shape="rectangle" ><!-- 這裏指定了我現在要畫的是一個矩形 -->
- <stroke
- android:width="1dip"
- android:color="#ff333333" /><!-- 這個就是一個畫筆啦,現在指定了畫筆的大小,還有顏色 -->
- <corners android:radius="12dip" /><!-- 現在這裏指定我這個矩形是圓角的,12是那個圓角的值 -->
- <solid android:color="@color/background" /><!-- 邊框顏色 -->
- <padding
- android:bottom="2dip"
- android:left="8dip"
- android:right="8dip"
- android:top="2dip" /><!-- 這個是內距 -->
- </shape></font></font>
- <font color="#333333"><font face="Arial"><?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:andro
- android:layout_width="150dip"
- android:layout_height="150dip"
- android:gravity="center_horizontal"
- android:orientation="vertical" >
-
- <ImageView
- android:
- android:layout_width="120dip"
- android:layout_height="120dip"
- android:scaleType="fitXY"
- android:src="@drawable/app"
- android:contentDescription="@string/hello_world"/>
-
- <TextView
- android:
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="5dip"
- android:textSize="18sp"
- android:textColor="@android:color/black"
- android:text="@string/main"
- android:background="@drawable/text_background"/><!-- 引用剛剛定義的圖片,像一般圖片一樣使用就行的啦,很方便的 -->
- </LinearLayout>
- </font></font>
- <activity
- android:theme="@android:style/Theme.NoTitleBar"
- android:label="@string/main"
- android:name="com.xiaobin.security.ui.MainActivity" />
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:andro
- 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="40dip"
- android:background="@drawable/title_background"
- android:gravity="center_vertical|center_horizontal"
- android:orientation="vertical" >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/main"
- android:textColor="@android:color/white"
- android:textSize="22sp" />
- </LinearLayout>
- <GridView
- android:
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:numColumns="2"
- android:verticalSpacing="8dip" />
- </LinearLayout>



最後更新:2017-04-03 14:54:32