2015-10-02 17 views
1

这是一个没有键盘,屏幕:如何在键盘上升时调整列表视图的大小?

http://i.stack.imgur.com/YOnMf.png

但是,当我点击的EditText和键盘上升,头弄乱了和消失,因为它会涨得:

http://i.stack.imgur.com/zyJ3j.png

这是代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
tools:context=".SecondActivity" 
android:background="@color/white"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="55dp" 
    android:id="@+id/abs" 
    android:orientation="horizontal" 
    android:layout_alignParentTop="true" 
    android:gravity="center"> 

     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:id="@+id/btnVoltar" 
      android:src="@drawable/inochat" 
      android:layout_marginLeft="3dp"/> 

     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:id="@+id/usu" 
      android:src="@drawable/usuario" 
      android:layout_alignParentRight="true" 
      android:background="@drawable/foto" 
      android:layout_marginRight="2dp" 
      android:layout_marginTop="3dp"/> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_toLeftOf="@+id/addfavorito" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="Nome" 
      android:id="@+id/nomeoutro" 
      android:layout_centerVertical="true" 
      android:layout_toRightOf="@+id/btnVoltar" 
      android:layout_toEndOf="@+id/btnVoltar" 
      android:textColor="#000000" 
      android:textSize="15dp" 
      android:layout_marginLeft="5dp"/> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:src="@drawable/traco" 
      android:layout_alignParentBottom="true"/> 

     <ImageButton 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:id="@+id/addfavorito" 
      android:layout_centerVertical="true" 
      android:layout_toStartOf="@+id/usu" 
      android:src="@drawable/fav"/> 
</RelativeLayout> 

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/swipe_refresh_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/llMsgCompose" 
    android:layout_below="@+id/abs"> 

    <ListView 
     android:isScrollContainer="false" 
     android:layout_above="@+id/llMsgCompose" 
     android:id="@+id/txtMensagens" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@null" 
     android:divider="@null" 
     android:transcriptMode="alwaysScroll"> 
    </ListView> 

</android.support.v4.widget.SwipeRefreshLayout> 

<RelativeLayout 
    android:id="@+id/llMsgCompose" 
    android:layout_width="match_parent" 
    android:layout_height="40dp" 
    android:background="@color/white" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="1dp" 
    android:gravity="center"> 

    <EditText 
     android:id="@+id/txtMensagem" 
     android:layout_width="50dp" 
     android:layout_height="fill_parent" 
     android:background="@color/bg_msg_input" 
     android:textColor="@color/text_msg_input" 
     android:paddingLeft="6dp" 
     android:paddingRight="6dp" 
     android:inputType="text" 

     android:layout_alignParentRight="true" 
     android:layout_toRightOf="@+id/icone"/> 

    <ImageView 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:id="@+id/icone" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:background="@color/bg_msg_input" 
     android:src="@drawable/msg"/> 
</RelativeLayout> 

</RelativeLayout> 
+0

尝试添加机器人:windowSoftInputMode = “adjustResize” 在您的活动代码在清单或Android:windowSoftInputMode =” adjustPan“ – Aakash

回答

1

尝试增加吨他以下为此次活动的清单:

机器人:windowSoftInputMode = “adjustPan”

机器人之间的区别:windowSoftInputMode = “adjustPan”机器人:windowSoftInputMode = “adjustResize”

“adjustResize”

调整活动的窗口大小,为屏幕上的软键盘腾出空间。

“adjustPan”

的活动窗口的内容会自动平移,使目前的工作重点是永远不会阻止键盘。这样用户就可以看到他们正在输入的内容。这通常不如调整大小,因为用户可能需要关闭软键盘才能与窗口的遮蔽部分进行交互。

另外,请参阅本博客,

http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html

喜欢的东西,

<activity 
    android:label="@string/app_name" 
    android:name=".MainActivity" android:windowSoftInputMode="adjustNothing"> 
    <intent-filter> 
    <action android:name="android.intent.action.MAIN" /> 
    <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 
+0

我们试过了,但没有奏效。点击EditText时它仍然会上升。不过谢谢! –

+0

哦,可以试试这个吗? android:windowSoftInputMode =“adjustNothing” – dhun

+0

我们已经试过了。由于某种原因,Manifest中没有任何标签不能像我们想要的那样工作。 –

相关问题