在安卓软件键盘打开时调整布局按钮



>我正在开发一个Android应用程序,其中我有一个文本框。我想要的是,在该文本框的单击上,键盘下方的布局按钮应该与键盘按钮一起可见,因为它们被键盘隐藏。我在 xml 中使用以下代码。

     <LinearLayout
            android:id="@+id/layout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" 
            android:layout_weight=".20">
        <EditText
            android:id="@+id/edittext1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:cursorVisible="false"
            android:ems="10"
            android:gravity="top"
            android:hint="Message : "
            android:inputType="textMultiLine"
            android:scrollbars="vertical"
            android:textColor="#000000"
            android:textSize="15sp"
            android:visibility="visible" />
    </LinearLayout>
   <LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".80"
    android:background="@drawable/albgbckgrnd"
    android:orientation="horizontal" >
    <ImageButton
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:layout_weight=".33"
        android:textSize="25sp"
        android:typeface="sans"
        android:visibility="visible" />
    <ImageButton
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:layout_weight=".33"
        android:textSize="25sp"
        android:typeface="sans"
        android:visibility="visible" />
    <ImageButton
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:layout_weight=".33"           
        android:textSize="25sp"
        android:typeface="sans"
        android:visibility="visible" />
</LinearLayout>

不知道该怎么做!请帮忙!谢谢!

使用

"adjustResize" 

根据安卓文档

活动的主窗口始终会调整大小,以便为屏幕上的软键盘腾出空间。

像这样将其添加到清单文件中的活动

  <activity android:name="YourActivityName" 
            android:windowSoftInputMode="adjustResize">

像这样更新布局

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp" >
    <LinearLayout
        android:id="@+id/layout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".20"
        android:orientation="horizontal" >
        <EditText
            android:id="@+id/edittext1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:cursorVisible="false"
            android:ems="10"
            android:gravity="top"
            android:hint="Message : "
            android:inputType="textMultiLine"
            android:scrollbars="vertical"
            android:textColor="#000000"
            android:textSize="15sp"
            android:visibility="visible" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".80"
        android:background="#ff00"
        android:orientation="horizontal" >
        <ImageButton
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight=".33"
            android:textSize="25sp"
            android:typeface="sans"
            android:visibility="visible" />
        <ImageButton
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight=".33"
            android:textSize="25sp"
            android:typeface="sans"
            android:visibility="visible" />
        <ImageButton
            android:id="@+id/button3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight=".33"
            android:textSize="25sp"
            android:typeface="sans"
            android:visibility="visible" />
    </LinearLayout>
</LinearLayout>

最新更新