問題的標題可能看起來與其他問題相似,但事實并非如此。我有幾個奇怪的問題,我無法解決。
我有一個 xml 布局,該布局的結構如下所示。
線性布局
|
滾動視圖
|
線性布局
|
文本視圖
編輯文本(多行)
xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"/>
<EditText
android:layout_width="match_parent"
android:inputType="textMultiLine"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
現在讓我們討論一下問題。如果我繼續向 editText 添加新行,editText 本身會滾動,并且位于 EditText 上方的 TextView 不會滾動。但我想要的是 EditText 不滾動并將作業留給 scrollView 以便在添加新 Line 時位于 EditText 上方的 textView 也與 EditText 一起滾動。
當我按下回傳時,ScrollView 表現正常(通常當 editText 不再聚焦時)。設定為
<ScrollView
...
layout_height="wrap_content">
解決問題,但所需的高度隨后受到影響。水平滾動視圖也會發生同樣的事情。
有沒有辦法解決這個問題?詳細的答案會有所幫助。
uj5u.com熱心網友回復:
將您EditText的高度設定為wrap_content使其擴展而不是滾動。將你LinearLayout的高度設定為wrap_content它的內容的大小,即TextView和EditText。
ScrollView應該是您想要的“視窗”進入內容布局的任何高度,即LinearLayout在ScrollView.
如果內容布局太大而無法在可見中顯示,則會發生滾動ScrollView,這就是為什么內容布局應該始終是wrap_content(內容的大小)而不是match_parent(滾動視圖“視窗”的大小)的原因。如果內容始終與滾動視圖大小相同,那么它們永遠不需要滾動,對嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/456309.html
標籤:安卓 安卓布局 android-edittext 滚动视图
