疯狂android 的一些笔记
16lz
2021-01-26
为了方便复习,就把写的东西保存在这了。
1.shape用于设定形状,可以在selector,layout等里面使用,有6个子标签
更详细:http://www.cnblogs.com/cyanfei/archive/2012/07/27/2612023.html
1 <?xml version="1.0" encoding="UTF-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android"> 3 <!-- solid 实心 填充的意思--> 4 <solid android:color="#0000"/> 5 6 <!-- gradient 渐变 7 ndroid:angle是渐变角度,必须为45的整数倍 8 9 -->10 <gradient android:startColor="#ff51ffe7"11 android:endColor="#7ff"12 android:type="linear"13 android:angle="270"14 />15 <!--stroke 描边16 android:dashWidth="5dp"17 android:dashGap="3dp 是虚线。18 -->19 <stroke android:color="#ffff6441" android:width="2dp"/>20 21 <!--圆角-->22 <corners android:radius="20dp"/>23 24 <!--间隔padding-->25 <padding26 android:left="10dp"27 android:right="10dp"28 android:bottom="10dp"29 android:top="10dp"30 />31 </shape>View Code
2.ToggleButton 状态开关 Switch 开关
main.xml:
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:id="@+id/boot" 4 android:orientation="vertical" 5 android:layout_width="fill_parent" 6 android:layout_height="fill_parent" 7 > 8 <ToggleButton 9 android:layout_width="200dip"10 android:layout_height="wrap_content"11 android:layout_marginLeft="20dip"12 android:typeface="sans"13 android:textOn="开启"14 android:textOff="关闭"15 android:id="@+id/toggleButton"16 />17 <LinearLayout18 android:layout_width="fill_parent"19 android:layout_height="wrap_content"20 android:id="@+id/LinerLayout"21 >22 <Button android:text="first button"23 android:layout_width="wrap_content"24 android:layout_height="wrap_content"/>25 <Button android:text="second button"26 android:layout_width="wrap_content"27 android:layout_height="wrap_content"/>28 <Button android:text="three button"29 android:layout_width="wrap_content"30 android:layout_height="wrap_content"/>31 </LinearLayout>32 </LinearLayout>View Code
1 package com.example.HxlTom; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.widget.CompoundButton; 7 import android.widget.LinearLayout; 8 import android.widget.TextView; 9 import android.widget.ToggleButton;10 11 import java.math.BigInteger;12 13 public class MyActivity extends Activity {14 /**15 * Called when the activity is first created.16 */17 int num = 0;18 @Override19 public void onCreate(Bundle savedInstanceState) {20 super.onCreate(savedInstanceState);21 setContentView(R.layout.main);22 23 final LinearLayout linearLayout = (LinearLayout)findViewById(R.id.LinerLayout);24 final ToggleButton toggleButton = (ToggleButton)findViewById(R.id.toggleButton);25 26 toggleButton.setOnCheckedChangeListener(new ToggleButton.OnCheckedChangeListener() {27 @Override28 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {29 if(!isChecked){30 linearLayout.setOrientation(LinearLayout.HORIZONTAL);31 }else{32 linearLayout.setOrientation(LinearLayout.VERTICAL);33 }34 }35 });36 BigInteger bigInteger = new BigInteger.ZERO;37 }38 }View Code
就是这个样子:
3.
android:layout_gravity 和 android:gravity 的区别
从名字上可以看到,android:gravity是对元素本身说的,元素本身的文本显示在什么地方靠着换个属性设置,不过不设置默认是在左侧的。
android:layout_gravity是相对与它的父元素说的,说明元素显示在父元素的什么位置。
比如说button: android:layout_gravity 表示按钮在界面上的位置。 android:gravity表示button上的字在button上的位置。
更多相关文章
- Android(安卓)自定义选项卡按钮和选项卡位置
- Google Map API Key 获得方法
- 在android中通过gps wifi定位位置
- ActionBar(2) 标题和渐变背景设置
- android 设置程序安装位置
- ImageButton一些总结
- Android中使用shape
- 【个人总结】Android几种常用布局的总结
- XML的解析中的三种方法