Android控件布局
1.TextView布局需要注意以下几个属性
1.设置宽度和高度 2.设置字体居中位置 3.设置显示行数和超长省略号 4.设置字体颜色和大小 5.设置字体的内边距和外边距 6.设置组件在父组件位置 7.组件ID 8.组件文字在text_default中设置了 1、2、3属性 text_h3_c7中设置了 4属性 在TextView设置 5、6、7、8属性
<!--TextView 默认的主题风格 1.默认宽高自适应 2.默认字体居中 3.默认单行显示并超出长度打省略号-->
<style name="text_default">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:singleLine">true</item>
<item name="android:ellipsize">end</item>
<item name="android:gravity">center</item>
</style>
<!--默认采用3号字体,7号颜色-->
<style name="text_h3_c7" parent="text_default">
<item name="android:textSize">@dimen/h3</item>
<item name="android:textColor">@color/skin_c7</item>
</style>
<!--字体的风格-->
<TextView
style="@style/text_h3_c7"
android:id="@+id/tv_app"
android:layout_margin="@dimen/margin10"
android:text="@string/app_name"
android:layout_gravity="center"
/>
<!--默认的字体大小-->
<dimen name="h1">18sp</dimen>
<dimen name="h2">16sp</dimen>
<dimen name="h3">15sp</dimen>
<dimen name="h4">13sp</dimen>
<dimen name="h5">12sp</dimen>
<dimen name="h6">11sp</dimen>
<dimen name="h7">10sp</dimen>
<!--设置默认的边距-->
<dimen name="margin1">1dp</dimen>
<dimen name="margin2">2dp</dimen>
<dimen name="margin3">3dp</dimen>
<dimen name="margin4">4dp</dimen>
<dimen name="margin5">5dp</dimen>
<dimen name="margin6">6dp</dimen>
<dimen name="margin7">7dp</dimen>
<dimen name="margin8">8dp</dimen>
<dimen name="margin9">9dp</dimen>
<dimen name="margin10">10dp</dimen>
<dimen name="margin11">11dp</dimen>
<dimen name="margin12">12dp</dimen>
<dimen name="margin13">13dp</dimen>
<dimen name="margin14">14dp</dimen>
<dimen name="margin15">15dp</dimen>
<dimen name="margin16">16dp</dimen>
<dimen name="margin17">17dp</dimen>
<dimen name="margin18">18dp</dimen>
<dimen name="margin19">19dp</dimen>
<dimen name="margin20">20dp</dimen>
<dimen name="margin21">21dp</dimen>
<dimen name="margin22">22dp</dimen>
<dimen name="margin23">23dp</dimen>
<dimen name="margin24">24dp</dimen>
<dimen name="margin25">25dp</dimen>
<dimen name="margin26">26dp</dimen>
<dimen name="margin27">27dp</dimen>
<dimen name="margin28">28dp</dimen>
<dimen name="margin29">29dp</dimen>
<dimen name="margin30">30dp</dimen>
<dimen name="margin31">31dp</dimen>
<dimen name="margin32">32dp</dimen>
<dimen name="margin33">33dp</dimen>
<dimen name="margin34">34dp</dimen>
<dimen name="margin35">35dp</dimen>
<dimen name="margin36">36dp</dimen>
<dimen name="margin37">37dp</dimen>
<dimen name="margin38">38dp</dimen>
<dimen name="margin39">39dp</dimen>
<dimen name="margin40">40dp</dimen>
<dimen name="margin41">41dp</dimen>
<dimen name="margin42">42dp</dimen>
<dimen name="margin43">43dp</dimen>
<dimen name="margin44">44dp</dimen>
<dimen name="margin45">45dp</dimen>
<dimen name="margin46">46dp</dimen>
<dimen name="margin47">47dp</dimen>
<dimen name="margin48">48dp</dimen>
<dimen name="margin49">49dp</dimen>
<dimen name="margin50">50dp</dimen>
<!--字体对应的颜色-->
<color name="skin_c1">#ffca3b</color>
<color name="skin_c2">#ffaf00</color>
<color name="skin_c3">#f67057</color>
<color name="skin_c4">#76cbf2</color>
<color name="skin_c5">#000000</color>
<color name="skin_c6">#444444</color>
<color name="skin_c7">#888888</color>
<color name="skin_c8">#cccccc</color>
<color name="skin_c9">#eaeaea</color>
<color name="skin_c10">#f1f1f1</color>
<color name="skin_c11">#ffffff</color>
<color name="c12_666666">#666666</color>
2.EditView布局
1.设置宽高 2.设置背景框 3.设置默认显示字体大小及颜色 4.设置软键盘属性(搜索属性) 5.设置单行显示 6.设置字体和颜色 7.设置输入类型 8、设置输入的长度 9、设置输入的字符 10设置边距
<!--设置鼠标属性 设置软键盘搜索属性-->
<EditText
android:id="@+id/et_input_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/search_edittext_shape"
android:hint="@string/input_activity_edit_hint"
android:textColorHint="@color/gray"
android:imeOptions="actionSearch"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/black"
android:textSize="14sp"
android:inputType="textCapWords"
android:maxLength="50"
android:digits="abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:textCursorDrawable="@drawable/input_edittext_cursor_shape"
android:paddingBottom="8dp"
android:paddingTop="8dp"
/>
2.监听字符输入变化和软键盘点击搜索变化
etInputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//在edit 字符串发生改变的时候进行监听
if (s.toString() == null || s.toString().isEmpty()) {
ibtnInputDelete.setVisibility(View.INVISIBLE);
mInputController.getAllHistoryInput();
} else {
ibtnInputDelete.setVisibility(View.VISIBLE);
try {
String message = URLEncoder.encode(s.toString().trim(), "UTF-8");
mInputController.inputMessage(message);
} catch (UnsupportedEncodingException e) {
LogUtil.i("input", e);
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
etInputSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
LogUtil.i("actionId"+actionId);
//如果软键盘上面的是搜索
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
clampTodetail();
LogUtil.i("IME_ACTION_SEARCH");
return true;
}
else if(actionId == EditorInfo.IME_ACTION_GO)
{
LogUtil.i("IME_ACTION_GO");
clampTodetail();
return true;
}
else if( event.getKeyCode()== KeyEvent.KEYCODE_ENTER && KeyEvent.ACTION_DOWN == event.getAction())
{
LogUtil.i("KEYCODE_ENTER");
clampTodetail();
return true;
}
return false;
}
});
3.Button布局
采用和Textview类似的style ,设置点击事件的时候可以加上水波纹适配ripple_again_study_bg.xml
drawable文件夹下面添加ripple_again_study_bg.xml文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/white_smoke_medium">
<item android:state_pressed="false">
<shape android:shape="rectangle">
<solid android:color="@color/white_smoke_light" />
<corners android:radius="0dp" />
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/gray_light" />
<corners android:radius="0dp" />
</shape>
</item>
</selector>
drawable-v21文件夹下面添加ripple_again_study_bg.xml文件
<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/gray_light"
android:radius="0dp"
>
<item>
<shape
android:shape="rectangle">
<solid android:color="@color/white_smoke_light" />
</shape>
</item>
</ripple>
4.ImageView布局
1.布局中的图片最好放在src里面
2.图片最好采用.9图片
<ImageView
android:id="@+id/iv_pk"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:background="@drawable/bt_pk3"
android:src="@drawable/bt_pk2" />