Android自定義Shape的屬性


Android xml資源文件中Shape的屬性:

 solid

       描述:內部填充

       屬性:android:color 填充顏色

  size

       描述:大小

       屬性:

                 android:width 寬

                 android:height 高

 gradient

        描述:漸變色

        屬性:

                   android:startColor漸變起始顏色

                   android:endColor漸變結束顏色

                   android:centerColor漸變中間顏色

                   android:angle 漸變的角度,angle=0時,漸變色是從左向右,然后逆時針方向轉;當angle=90時,漸變色從上往下。angle必然是45的倍數

                   android:type 漸變類型:linear(線性)、radial(放射性,以開始色為中心)、sweep(掃描線式漸變)

                   android:userLevel如果要使用LevelListDrawable對象,就要設置為true。設置true無漸變色,false有漸變色

                   android:grdientRadial漸變半徑,只有設置type為radial時,此值才生效

                   android:centerX 漸變中心X點坐標的相對位置

                   android:centerY 漸變中心Y點坐標的相對位置

stroke

        描述:描邊

        屬性:

                   android:width 描邊寬度

                   android:color 描邊顏色

                   android:dashwidth描邊樣式為虛線時的寬度,值為0時為實線,值大於0時為虛線

                   android:dashGap 描邊為虛線時,虛線之間的間隔

corners

        描述:圓角

        屬性:

                   android:radius 四個角半徑值

                   android:topLeftRadius左上角半徑值

                   android:topRightRadius右上角半徑值

                   android:bottomLeftRadius右下角半徑值

                   android:bottomRightRadius左下角半徑值

padding

        描述:內邊距

        屬性:

                   android:left 左內邊距

                   android:right 右內邊距

                   android:top 上內邊距

                   android:bottom 下內邊距

 

附 

/////////////////////////////////////////////////// 

然后在Activity里,直接使用

Resources res =getResources();

String[] city=res.getStringArray(R.array.city);

////////////////////////////////////////////////////

DisplayMetrics dm=new DisplayMetrics();

//                   getWindowManager().getDefaultDisplay().getMetrics(dm);

//                   String strPM=dm.widthPixels+"*"+dm.heightPixels;//獲取分辨率

                     /*Display display=getWindowManager().getDefaultDisplay();

                     Point size=new Point();//獲取屏幕長寬

                     display.getSize(size);*/

 

///////////////////////////////////////////////////////////

透明度計算

AA(startColorstr的前兩位)是代表不透明度的十六進制,00表示完全透明,FF就是全不透明,化成十進制的范圍就是0~255,剩下的RRGGBB就是顏色的十六進制代碼。如何把30%的不透明度轉換成十六制呢?很簡單,先計算#AA的的十進制x,x/255 = 3/10,解得x=3*255/10,然后再把x換算成十六進制,約等於4B。 

/////////////////////////////////////////////////////////////////

自定義對話框

Dialog dialog=new Dialog(this,R.style.dialog);

                     View view=getLayoutInflater().inflate(R.layout.classroom_info, null);

                     TextView txtJsName=(TextView)view.findViewById(R.id.txt_jsName);

                     TextView txtSiteCount=(TextView)view.findViewById(R.id.txt_siteCount);

                     TextView txtholdCount=(TextView)view.findViewById(R.id.txt_holdCount);

                     TextView txtsiteLeft=(TextView)view.findViewById(R.id.txt_siteLeft);

                     txtJsName.setText("第五教學樓101");

                     txtSiteCount.setText(21+"");

                     txtholdCount.setText(7+"");

                     txtsiteLeft.setText((21-7)+"");

                     dialog.setContentView(view);

                     dialog.setCanceledOnTouchOutside(true);

                     dialog.show();

對話框樣式

 <style name="dialog" parent="@android:style/Theme.Dialog">

        <item name="android:windowFrame">@null</item><!--邊框-->

        <item name="android:windowIsFloating">true</item><!--是否浮現在activity之上-->

        <item name="android:windowIsTranslucent">false</item><!--半透明-->

        <item name="android:windowNoTitle">true</item><!--無標題-->

       <!-- <item name="android:windowBackground">@color/alpha_bg</item>背景透明-->

        <item name="android:backgroundDimEnabled">false</item><!--模糊-->

    </style> 

////////////////////////////////////////////////////////////////////

文字跑馬燈效果

<TextView android:layout_width="100px"

        android:layout_height="wrap_content"

        android:textColor="@android:color/white"

        android:ellipsize="marquee"

        android:focusable="true"

        android:marqueeRepeatLimit="marquee_forever"

        android:focusableInTouchMode="true"

        android:scrollHorizontally="true"

        android:text="這才是真正的文字跑馬燈效果"

        >

    </TextView>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM