Android 开发笔记___shape

时间:2023-03-08 19:16:07

shape_oval

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" > <solid android:color="#ff66aa" /> <stroke
android:width="1dp"
android:color="#ffaaaaaa" /> </shape>

Android 开发笔记___shape

默认矩形

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#ffdd66" /> <stroke
android:width="1dp"
android:color="#ffaaaaaa" /> <corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" /> </shape>

Android 开发笔记___shape

xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <View
android:id="@+id/v_content"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="20dp" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <Button
android:id="@+id/btn_rect"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="圆角矩形背景"
android:textColor="#000000"
android:textSize="17sp" /> <Button
android:id="@+id/btn_oval"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="椭圆背景"
android:textColor="#000000"
android:textSize="17sp" /> </LinearLayout> </LinearLayout>

java

 package com.example.alimjan.hello_world;

 import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button; /**
* Created by alimjan on 7/1/2017.
*/ public class class__2_4_3 extends AppCompatActivity implements View.OnClickListener { private View v_content; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.code_2_4_3);
v_content = (View) findViewById(R.id.v_content); Button btn_rect = (Button) findViewById(R.id.btn_rect);
Button btn_oval = (Button) findViewById(R.id.btn_oval);
btn_rect.setOnClickListener(this);
btn_oval.setOnClickListener(this);
} @Override
public void onClick(View v) {
if (v.getId() == R.id.btn_rect) {
v_content.setBackgroundResource(R.drawable.shape_rect_gold);
} else if (v.getId() == R.id.btn_oval) {
v_content.setBackgroundResource(R.drawable.shape_oval_rose);
}
} public static void startHome(Context mContext) {
Intent intent = new Intent(mContext, class__2_4_3.class);
mContext.startActivity(intent);
} }

Android 开发笔记___shapeAndroid 开发笔记___shape

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:描边的厚度