用户登录
用户注册

分享至

2020-10-09

  • 作者: 你觉得我这朵菊花看起来美闻起来香吗
  • 来源: 51数据库
  • 2021-07-11

Android的一些布局小知识点

1.布局的背景可以引入一个layout-list.xml代表设置变换的图片,布局上面 中间 结束的颜色不同

<?xml version="1.0" encoding="utf-8"?>

layer-listxmlns:android=“http://schemas.android.com/apk/res/android”

<gradientandroid:startColor="#ffa6a6a6"
android:centerColor="#ffdbdbdb"
android:endColor="#ffe7e7e7"
android:height=“1px”
android:angle=“90”
android:dither=“true” />

2.在TextView里面可以引入shadowDx,shadowDy,shadowColor来设置阴影
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginTop=“20dip”
android:gravity=“bottom”
android:shadowColor="#FFFFFF"

android:shadowDx=“0”
android:shadowDy=“2”
android:shadowRadius=“1”
android:text="@string/app_name"
android:textColor="#444444"
android:textSize=“35dip”
android:typeface=“serif” >

3 如果要去掉标题栏一种在是代码中写一种是在布局文件中添加
布局文件:android:theme="@android:style/Theme.NoTitleBar"
4.获取版本号:获取应用程序版本号
private String getVersion() {
try {
PackageInfo info = getPackageManager().getPackageInfo(
getPackageName(), 0);
return info.versionName;
} catch (Exception e) {
e.printStackTrace();
// 包名没有找到的异常是不会发生的 通常会加一个 can’t reach10 return null;
} }
5.判断手机是否有网络连接
private boolean isNetWorkAvaiable(){
//系统里面提供的网络访问状况相关的服务 3 ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo info =cm.getActiveNetworkInfo();
if(info!=null){
return info.isAvailable();
}else{
return false;
} }

6.TabHost的颜色选择器
<selector

xmlns:android=“http://schemas.android.com/apk/res/android”>
//被选中的时候 没有被选中的时候3 <itemandroid:drawable="@drawable/tab_main_nav_on" android:state_selected=“true”/>
<item android:drawable="@drawable/tab_main_nav_off"android:state_selected=“false”/>

7.如果一个应用程序有大量的相同的类似的布局。布局我们可以抽取出来

merge:代表当前布局可以被别的布局直接引用。
include:代表引用一个别的布局
但采用这种方法会降低系统的效率
8.设置ListView的间隔线条
divider=“color/transparent” //间隔线条为透明2 dividerHeight=“5.0dip” //为5个dip3 listSelector="" //设置点中时颜色4
代码设置分隔符 setDivider(new ColorDrawable(Color.TRANS));
//第一个参数context 第二个参数引入的布局 第三个参数 需要设置的内容的ID,第四个参数对应需要设置的内容8 lv.setAdapter(new ArrayAdapter(this,R.layout.fav_item,R.id.fav_title,strs));

软件
前端设计
程序设计
Java相关