• 【转】EditText大小(长宽)的多种设置方式----不错


    原文网址:http://orgcent.com/android-edittext-ems-layout-minwidth-maxheight/

    EditText大小的设置有多种方式,要想对每种方式运用自如必须熟练掌握它们。下面将对其详细描述:

    1、layout_width和layout_height
    layout_width告诉父容器EditText需要的宽度,layout_height则设置需要的高度。单位建议为dp,关于Android中单位转换问题可以参考Android根据分辨率进行单位转换-(dp,sp转像素px)

    2、minWidth/maxHeight和minHeight/maxHeight
    这些属性用来动态的限制EditText的大小,应用场景有如下几种情况:
    1)在没有内容情况下,通过min系列保证控件的最小宽高,保持界面整体美观。
    2)在内容过多情况下,使用max系列来限制控件大小,确保不影响界面上的其他控件。
    PS:还可以使用minLines和maxLines来限制内容显示的行数。

    3、ems、minEms和maxEms
    ems指的是字体的宽度。此属性在Android中用来设置EditText的宽度,即设置EditText为n个字符的宽度。
    PS:android:layout_width必须为wrap_content,否则ems将无效。

    参考代码:

    <EditText 
           android:id="@+id/etTest" 
           android:layout_width="wrap_content"
           android:layout_height="wrap_content" android:ems="4"/>
     
    原文网址:http://www.jb51.net/article/32794.htm

    Android取消EditText自动获取焦点默认行为

    在项目中,一进入一个页面, EditText默认就会自动获取焦点,很是郁闷,Android 如何让EditText不自动获取焦点?于是搜集整理一番,晒出来和大家分享,希望对你们有所帮助

    那么如何取消这个默认行为呢? 
    在网上找了好久,有点 监听软键盘事件,有点 调用 clearFouse()方法,但是测试了都没有! xml中也找不到相应的属性可以关闭这个默认行为 
    解决之道:在EditText的父级控件中找一个,设置成 
    代码如下:

    android:focusable="true" 
    android:focusableInTouchMode="true" 

    这样,就把EditText默认的行为截断了! 

    <LinearLayout 
    style="@style/FillWrapWidgetStyle" 
    android:orientation="vertical" 
    android:background="@color/black" 
    android:gravity="center_horizontal" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 

    <ImageView 
    android:id="@+id/logo" 
    style="@style/WrapContentWidgetStyle" 
    android:background="@drawable/dream_dictionary_logo" 
    /> 
    <RelativeLayout 
    style="@style/FillWrapWidgetStyle" 
    android:background="@drawable/searchbar_bg" 
    android:gravity="center_vertical" 

    <EditText 
    android:id="@+id/searchEditText" 
    style="@style/WrapContentWidgetStyle" 
    android:background="@null" 
    android:hint="Search" 
    android:layout_marginLeft="40dp" 
    android:singleLine="true" 
    /> 
    </RelativeLayout> 
    </LinearLayout> 
     
  • 相关阅读:
    [LeetCode] 638. Shopping Offers
    [LeetCode] 1436. Destination City
    [LeetCode] 405. Convert a Number to Hexadecimal
    [LeetCode] 1909. Remove One Element to Make the Array Strictly Increasing
    [LeetCode] 1475. Final Prices With a Special Discount in a Shop
    [LeetCode] 650. 2 Keys Keyboard
    [LeetCode] 1382. Balance a Binary Search Tree
    [LeetCode] 917. Reverse Only Letters
    [LeetCode] 1189. Maximum Number of Balloons
    [LeetCode] 447. Number of Boomerangs
  • 原文地址:https://www.cnblogs.com/wi100sh/p/4471264.html
Copyright © 2020-2023  润新知