【问题标题】:Move Layouts when opening the EditText Keyboard打开 EditText 键盘时移动布局
【发布时间】:2016-01-23 19:31:59
【问题描述】:

我正在创建控制台或终端,但遇到了问题。通常我的活动看起来像这样:

但是当我点击edittext并且键盘打开我的edittextfield并且我的发送按钮消失了:

但我希望编辑文本和发送按钮位于键盘上方,这样您就可以看到您正在输入的内容并且可以发送它。这是我的 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"
    android:background="#d1d1d1">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="477dp"
        android:layout_below="@+id/title" >>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/textView"
                android:text="Console:"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="0dip"
                android:gravity="top"
                android:textSize="20sp"
                android:textColor="#000000"
                android:typeface="monospace"
                android:paddingLeft="0dp"/>
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="1">

        <EditText
            android:layout_marginLeft="5dp"
            android:layout_width="163dp"
            android:layout_height="wrap_content"
            android:id="@+id/consoleText"
            android:layout_weight="0.92" />

        <Button
            android:layout_width="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="5dp"
            android:layout_height="wrap_content"
            android:text="Send"
            android:id="@+id/sendButton"
            android:layout_gravity="right" />
    </LinearLayout>

</LinearLayout>

也许有人知道,我该如何解决这个问题!在此先感谢,任何帮助表示赞赏:)

【问题讨论】:

    标签: java android xml


    【解决方案1】:

    设置ScrollViewlayout_weight=1 应该可以工作。试试这个

    <?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"
        android:background="#d1d1d1">
    
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/textView"
                android:text="Console:"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="0dip"
                android:gravity="top"
                android:textSize="20sp"
                android:textColor="#000000"
                android:typeface="monospace"
                android:paddingLeft="0dp"/>
        </LinearLayout>
    </ScrollView>
    
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <EditText
            android:layout_marginLeft="5dp"
            android:layout_width="163dp"
            android:layout_height="wrap_content"
            android:id="@+id/consoleText"
            android:layout_weight="0.92" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="5dp"
            android:layout_height="wrap_content"
            android:text="Send"
            android:id="@+id/sendButton"
            android:layout_gravity="right" />
    </LinearLayout>
    
    </LinearLayout>
    

    【讨论】:

    • 很好用,你可能知道我如何以编程方式跳转/滚动到滚动视图的末尾,因为我在控制台中将文本附加到这个文本视图,我想跳到最后每当我发送新命令/按下按钮时,我的滚动视图中的这个 textview :)
    • 请检查此stackoverflow.com/questions/3080402/… 以将ScrollView 滚动到底部。
    猜你喜欢
    • 2017-09-09
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多