解决EditText不能撑满全屏的问题及EditText你应该知道的属性
生活随笔
收集整理的這篇文章主要介紹了
解决EditText不能撑满全屏的问题及EditText你应该知道的属性
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一般我們要實現去下圖一的效果很簡單: 兩個EditText就搞定 效果圖一: 但是我們想讓第二個EditText撐滿剩余空間怎么做?如效果圖二 效果圖二: 解決:
來源:?http://blog.sina.com.cn/s/blog_6cf2ea6a0102v61f.html
使用了ScrollView嵌套LinearLayout,將ScrollView中android:fillViewport設置為true。
分析:
當ScrollView里的元素想填滿ScrollView時,使用"fill_parent"是不管用的,必需為ScrollView設置:android:fillViewport="true"。
當ScrollView沒有fillVeewport=“true”時, 里面的元素(比如LinearLayout)會按照wrap_content來計算(不論它是否設了"fill_parent"),而如果 LinearLayout的元素設置了fill_parent,那么也是不管用的,因為LinearLayout依賴里面的元素,而里面的元素又依賴 LinearLayout,這樣自相矛盾.所以里面元素設置了fill_parent,也會當做wrap_content來計算.
來源:?http://blog.sina.com.cn/s/blog_6cf2ea6a0102v61f.html
?
代碼如下,注釋了常用的EditText屬性: <ScrollViewandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:fillViewport="true"> //*******************關鍵處********<LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><EditTextandroid:id="@+id/edit_title"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="center|left"android:layout_marginLeft="16dp"android:layout_marginRight="16dp"android:background="@null" //控件背景,這里沒有,指透明android:ellipsize="end" //自動隱藏尾部溢出數據,一般用于文字內容過長一行無法全部顯示時android:hint="添加標題"android:paddingBottom="10dp"android:paddingTop="10dp"android:singleLine="true" //強制輸入的內容在單行android:textColorHint="#bfbfbf" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="2dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:background="@drawable/dotted_line"android:layerType="software" /><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"><EditTextandroid:id="@+id/edit_content"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginLeft="16dp"android:layout_marginRight="16dp"android:layout_marginTop="16dp"android:gravity="left|top" //輸入時光標在左上角android:hint="內容"android:lineSpacingExtra="4.6dp" //設置行間距android:scrollbars="vertical" // 設置滾動條顯示android:textColorHint="#bfbfbf"android:textSize="16sp" /></RelativeLayout><!--android:background="@null" //去掉EditView的邊框android:inputType="textMultiLine" //可以顯示多行android:minLines="6" // 設置文本的最小行數--></LinearLayout></ScrollView>轉載于:https://www.cnblogs.com/yjing/p/5314938.html
總結
以上是生活随笔為你收集整理的解决EditText不能撑满全屏的问题及EditText你应该知道的属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到红色彼岸花是什么意思
- 下一篇: 做梦梦到鱼和黄鳝是什么意思