Android 開發筆記___shape

來源:互聯網
上載者:User

標籤:shape   滾動   class   amp   pad   屬性   填充   間隔   尺寸   

shape_oval

 1 <?xml version="1.0" encoding="utf-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android" 3     android:shape="oval" > 4  5     <solid android:color="#ff66aa" /> 6  7     <stroke 8         android:width="1dp" 9         android:color="#ffaaaaaa" />10 11 </shape>

 

 

預設矩形

 1 <?xml version="1.0" encoding="utf-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android" > 3  4     <solid android:color="#ffdd66" /> 5  6     <stroke 7         android:width="1dp" 8         android:color="#ffaaaaaa" /> 9 10     <corners11         android:bottomLeftRadius="10dp"12         android:bottomRightRadius="10dp"13         android:topLeftRadius="10dp"14         android:topRightRadius="10dp" />15 16 </shape>

 

xml

 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     android:orientation="vertical"> 6  7     <View 8         android:id="@+id/v_content" 9         android:layout_width="match_parent"10         android:layout_height="200dp"11         android:layout_margin="20dp" />12 13     <LinearLayout14         android:layout_width="match_parent"15         android:layout_height="wrap_content"16         android:orientation="horizontal">17 18         <Button19             android:id="@+id/btn_rect"20             android:layout_width="0dp"21             android:layout_height="wrap_content"22             android:layout_weight="1"23             android:text="圓角矩形背景"24             android:textColor="#000000"25             android:textSize="17sp" />26 27         <Button28             android:id="@+id/btn_oval"29             android:layout_width="0dp"30             android:layout_height="wrap_content"31             android:layout_weight="1"32             android:text="橢圓背景"33             android:textColor="#000000"34             android:textSize="17sp" />35 36     </LinearLayout>37 38 </LinearLayout>

 

java

 1 package com.example.alimjan.hello_world; 2  3 import android.content.Context; 4 import android.content.Intent; 5 import android.os.Bundle; 6 import android.support.v7.app.AppCompatActivity; 7 import android.view.View; 8 import android.widget.Button; 9 10 /**11  * Created by alimjan on 7/1/2017.12  */13 14 public class class__2_4_3 extends AppCompatActivity implements View.OnClickListener {15 16     private View v_content;17 18     @Override19     protected void onCreate(Bundle savedInstanceState) {20         super.onCreate(savedInstanceState);21         setContentView(R.layout.code_2_4_3);22         v_content = (View) findViewById(R.id.v_content);23 24         Button btn_rect = (Button) findViewById(R.id.btn_rect);25         Button btn_oval = (Button) findViewById(R.id.btn_oval);26         btn_rect.setOnClickListener(this);27         btn_oval.setOnClickListener(this);28     }29 30     @Override31     public void onClick(View v) {32         if (v.getId() == R.id.btn_rect) {33             v_content.setBackgroundResource(R.drawable.shape_rect_gold);34         } else if (v.getId() == R.id.btn_oval) {35             v_content.setBackgroundResource(R.drawable.shape_oval_rose);36         }37     }38 39     public static void startHome(Context mContext) {40         Intent intent = new Intent(mContext, class__2_4_3.class);41         mContext.startActivity(intent);42     }43 44 }

 

 1、shape 有四種類型

  rectangle  矩形

  oval    橢圓(corners屬性失效)

  line    直線(必須設定stroke屬性)

  ring    圓環

 2、corners

  bottomLeftRadius:左下角

  bottomRightRadius:右下角

  topLeftRadius:左上方

  topRightRadius:右上方

3、gradien(色彩坡形)

  linear:線性漸層

  radial:放射漸層

  sweep:滾動漸層

4、padding   間隔大小

5、size  圖形尺寸大小

6、solid  內部填充顏色

7、stroke 四周變現

  color:

  dashGap:每段虛線之間間隔

  dashWidth:每段虛線寬度

  width:描邊的厚度

 

Android 開發筆記___shape

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.