android的自定義屬性
㈠ android自定義listview item間距顏色屬性,
也就是2個item之間的那根線是吧,ListView自己提供了方法的,ListView.setDivider(「你要修改的顏色(最好放一張圖片)」);就是這個方法,可以解決你的問題。
㈡ android中xml中有些控制項的屬性裡面有 "app:.." ,此處的app:是什麼意思和一般的android:有什麼區別
區別是:這兩個是聲明的不同的命名空間,android的是系統的,app是自定義的。
Android自定義控制項的屬性,在xml中使用自己自定義的attr的時候,其中有一步就是要自定義一個xml的命名空間後然後再給自定義屬性賦值,現在發現不知道什麼時候開始Android把這個改了,現在發現可以統一用
xmlns:app="http://schemas.android.com/apk/res-auto"
而不是原來的:
xmlns:app="http://schemas.android.com/apk/App的Package名"
還有人提到在作為lib被使用的時候,也應該用res-auto
所以說區別就是如果你http://schemas.android.com/apk/後面寫的是res/包名,那就是相關包名下的自定義屬性,而res-auto就是所有的自定義包名。
㈢ android 自定義控制項 屬性怎麼用
自定義屬性設置
public class lei extends RelativeLayout {
private TextView tv1
public lei(Context context) {
super(context);
}
public lei(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.item,this);
tv1 = findViewById(R.id.tv1);
TypedArray array = context.obtainStyledAttributes(attrs,R.styleable.lei);
String str1 = (String) array.getText(R.styleable.lei_settitle);
int str2 = array.getColor(R.styleable.lei_setbackgroudcolor,Color.BLACK);
tv1.setText(str1);
tv1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getContext(), "toast", Toast.LENGTH_SHORT).show();
}
});
array.recycle();
}
}
布局控制項
<com.example.administrator.myapplication.lei
android:id="@+id/ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
cs:setbackgroudcolor="#158616"
cs:settitle="這個是標題"
cs:settitletextcolor="#FFFFFF"
cs:settextrcolor="#FFFFFF"
>
</com.example.administrator.myapplication.lei>
屬性設置
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="lei" >
<attr name="setbackgroudcolor" format="color|reference"/>
<attr name="settitle" format="string|reference"/>
<attr name="settextrcolor" format="color"/>
<attr name="settitletextcolor" format="color"/>
</declare-styleable>
</resources>
㈣ android 使用requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);來自定義標題,但是運行程序後就會出。
對於Activity系統會默認添加android:theme屬性而這個默認的屬性帶有默認的title,所以你要覆蓋這個屬性,不然的話就相當於一個Activity有兩個title所以會出現運行異常,新添加的theme屬性值裡面應該不能有有title。
將對應的Activity添加屬性android:theme="@android:style/Theme.Light"可正常運行
㈤ android開發scaletype自定義屬性中怎麼寫
ImageView.ScaleType.CENTER|android:scaleType="center" 以原圖的幾何中心點和ImagView的幾何中心點為基準,按圖片的原來size居中顯示,不縮放,當圖片長/寬超過View的長/寬,則截取圖片的居中部分顯示ImageView的size.當圖片小於View 的長寬時,只顯示圖片的size,不剪裁。
ImageView.ScaleType.CENTER_CROP|android:scaleType="centerCrop" 以原圖的幾何中心點和ImagView的幾何中心點為基準,按比例擴大(圖片小於View的寬時)圖片的size居中顯示,使得圖片長 (寬)等於或大於View的長(寬),並按View的大小截取圖片。當原圖的size大於ImageView時,按比例縮小圖片,使得長寬中有一向等於ImageView,另一向大於ImageView。實際上,使得原圖的size大於等於ImageView
ImageView.ScaleType.CENTER_INSIDE|android:scaleType="centerInside" 以原圖的幾何中心點和ImagView的幾何中心點為基準,將圖片的內容完整居中顯示,通過按比例縮小原來的size使得圖片長(寬)等於或小於ImageView的長(寬)
ImageView.ScaleType.FIT_CENTER|android:scaleType="fitCenter" 把圖片按比例擴大(縮小)到View的寬度,居中顯示
ImageView.ScaleType.FIT_END|android:scaleType="fitEnd" 把圖片按比例擴大(縮小)到View的寬度,顯示在View的下部分位置
ImageView.ScaleType.FIT_START|android:scaleType="fitStart" 把圖片按比例擴大(縮小)到View的寬度,顯示在View的上部分位置
ImageView.ScaleType.FIT_XY|android:scaleType="fitXY" 把圖片按照指定的大小在View中顯示,拉伸顯示圖片,不保持原比例,填滿View.
ImageView.ScaleType.MATRIX|android:scaleType="matrix" 用matrix來繪制
依本人之見,scaletype的種類分為三類matrix(默認)、fit-X類、和center類。matrix就不多說。fit-X類中,
fitStart、fitCenter和fitEnd之間的都是根據需要使原圖改變對ImgView進行適應,不剪裁,按matrix進行繪制,但它們
的區別在於基準不同。fitStart的基準為最上角的點(即matrix方式開始的點)fitCenter的基準點為中間的點
(matrix方式中可以使圖片居中的點),而fitEnd的基準點為右下角的點(即matrix方式最後繪制點)。center類
中,center、centerCrop、centerInside都是以原圖的幾何中心點和ImagView的幾何中心點為基準,且只繪制
ImagView大小的圖像,不同的是是否保持原圖大小和繪圖的目標不同、採取的手段不同
㈥ 如何在android style文件中使用自定義屬性
在style文件中定義屬性我知道: 18.0sp @drawable/skin_color_button @drawable/common_btn_green 使用style我也知道: 但你說的在style中使用自定義屬性我有點迷糊。style中不就是自定義的屬性嗎?
㈦ Android自定義屬性,format詳解
1. reference:參考某一資源ID。
(1)屬性定義:
(2)屬性使用:
2. color:顏納緩色值。
(1)屬性定義:
(洞畝模2)屬性使用:
3. boolean:布爾值。
(1)屬性定義:
(2)屬性使用:
4. dimension:尺寸值。
(2)屬性使用耐如:
5. float:浮點值。
(1)屬性定義:
(2)屬性使用:
6. integer:整型值。
(1)屬性定義:
(2)屬性使用:
android:interpolator = "@anim/動畫ID"
android:fromDegrees = "0"
android:toDegrees = "360"
android:pivotX = "200%"
android:pivotY = "300%"
android:ration = "5000"
android:repeatMode = "restart"
android:repeatCount = "infinite"
/>