android xml布局文件相关问题

1.textview的限制字数

通过android:maxEms与android:singleLine属性结合实现该功能。

<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxEms="18"
android:singleLine="true"
android:ellipsize="end"
/>

as中用maxlins了,现在

    android:maxEms="6"
          android:maxLines="1"
            android:ellipsize="end"

2.include的margin无法直接用

不仅margin不能用,和background也不能用,
可以用linelayout包起来,设置linelayout;
或者在上面用
或者在代码里:(不推荐)像素,不好适配,当然也可以适配,获取dpi

        LinearLayout llSelect = (LinearLayout) findViewById(R.id.ll_select_year_month);
//        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//        lp.setMargins(39, 10, 39, 0);
//
//        llSelect.setLayoutParams(lp);

巧用view

3.巧用layout_weight

4.button设置不可点击,不抢焦点

  android:id="@+id/imgbtn_right"
                style="@style/Titleright"
                android:focusable="false"
                android:enabled="false"
                android:onClick="null"
                android:layout_alignParentRight="true"

5.设置布局的shape

边框,边框颜色,填色,倒角等

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    android:shape="rectangle">
    <!--设置圆角渐变颜色-->
    <!--<gradient android:startColor="#FFFF0000"
    android:endColor="#80FF00FF"
    android:angle="270" />-->
    <!--设置内容离边界的距离-->
   <!-- <padding
        android:left="10dp"
        android:right="10dp"
        android:top="10dp"
    android:bottom="10dp" />-->
    <!--设置填充颜色-->
    <solid android:color="#ffffffff" />
    <!--设置描边颜色-->
  <!--  <stroke android:width="2.0dip"
    android:color="#b4ffffff"
    android:dashWidth="3.0dip"
    android:dashGap="0.0dip" />-->
    <!--设置圆角-->
    <corners android:radius="5dp" />
 <!--或  二选一  -->
 <corners android:topRightRadius="5dp"
        android:bottomRightRadius="5dp"  />
</shape>

关键字说明
solid:实心,就是填充的意思
android:color指定填充的颜色

gradient:渐变
android:startColor和android:endColor分别为起始和结束颜色,ndroid:angle是渐变角度,必须为45的整数倍。
另外渐变默认的模式为android:type=”linear”,即线性渐变,可以指定渐变为径向渐变,android:type=”radial”,径向渐变需要指定半径android:gradientRadius=”50”。

stroke:描边
android:width=”2dp” 描边的宽度,android:color 描边的颜色。
我们还可以把描边弄成虚线的形式,设置方式为:
android:dashWidth=”5dp”

android:dashGap=”3dp”
其中android:dashWidth表示’-‘这样一个横线的宽度,android:dashGap表示之间隔开的距离。

corners:圆角
android:radius为角的弧度,值越大角越圆。
布局中,使用include,在java代码里用
setbackgroundresource
tvwMonth.setBackgroundResource(R.drawable.shape_right_press_green);

5.1输入框光标问题

修改Android EditText光标颜色:
EditText有一个属性:android:textCursorDrawable,这个属性是用来控制光标颜色的
android:textCursorDrawable=”@null”,”@null”作用是让光标颜色和text color一样
Android 设置EditText光标Cursor颜色及粗细:
在android的输入框里,如果要修改光标的颜色及粗细步骤如下两步即可搞定:
1.在资源文件drawable下新建一个光标控制color_cursor.xml

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

设置EditText的光标为显示/隐藏
android:cursorVisible=”true”//显示
android:cursorVisible=”false”//隐藏
注:默认显示
// 光标默认显示问题,在魅族MX6上默认不会显示。(最好代码控制光标的显示与隐藏)

6.listview、button选中黄色

android:listSelector="@android:color/transparent"  

6.2listview scrollview 拉到底的色块变形问题

暂时忘记,后期补充

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不对法

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值