3

我已经阅读了很多帖子,似乎无法找到如何去做。如何避免在RelativeLayout上显示softkeyboard的元素重叠

我正在尝试创建以下布局xml。

在中间我想要一个带有一些按钮的LinearLayout,并且在LinearLayout的顶部和开始之间我想要一个textView。

的LinearLayout滚动型是内RelativeLayout的

我通过把的LinearLayout和TextView的一个RelativeLayout的内部实现这里面。 LinearLayout位于父级的中心,textView位于linearLayout之上并位于父级的顶部。文本垂直居中。

问题在于键盘开启时。我只在ScrollView中放置了LinearLayout。 如果我在清单中使用adjustPan,则没有任何反应,我无法滚动。如果我使用adjustResize,那么文本视图会出现在LinearLayout的顶部而不是上面。那我该怎么做呢?还是不可能? 我只想要linearLayout可以滚动,如果需要的话。 下面是代码:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:background="@color/black_overlay" 
       android:animateLayoutChanges="true" 
       android:hapticFeedbackEnabled="true" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 



    <ScrollView 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:fillViewport="true" 
     android:layout_centerInParent="true" 
     android:id="@+id/scrollView" 

     > 



     <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:layout_gravity="center_horizontal" 
       android:id="@+id/mLayout" 
       > 
    <Button 

      android:layout_marginBottom="10dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Match" 
      android:id="@+id/btn_newMatch" 
      style="@style/ButtonBar" 
      android:typeface="monospace"/> 
    <Button 
      android:layout_marginBottom="10dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Manage Matches" 
      android:id="@+id/btn_manageMatches" 
      style="@style/ButtonBar" 
      android:typeface="monospace"/> 
    <Button 
      android:layout_marginBottom="10dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Manage Teams" 
      android:id="@+id/btn_manageTeams" 
      style="@style/ButtonBar" 
      android:typeface="monospace"/> 
    <Button 
      android:layout_marginBottom="10dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Settings" 
      android:id="@+id/btn_settings" 
      style="@style/ButtonBar" 
      android:typeface="monospace"/> 
    <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Logout" 
      android:id="@+id/btn_logout" 
      style="@style/ButtonBar" 
      android:typeface="monospace"/> 
     </LinearLayout> 


</ScrollView> 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:text="Name" 
      android:typeface="monospace" 
      android:layout_above="@id/scrollView" 
      android:layout_alignParentTop="true" 
      android:gravity="center" 
      android:textSize="50dp" 
      android:textAppearance="?android:textAppearanceMediumInverse" 
      android:layout_marginBottom="10dp" 
      android:layout_marginTop="10dp"/> 
</RelativeLayout> 

这是怎么了目前与adjustResize样子:

没有键盘:http://i.stack.imgur.com/Y7WNo.jpg

随着键盘:http://i.stack.imgur.com/MlWpg.jpg

可有人点我在正确的方向?

Thx !!! :)

回答

0

只需添加这

android:windowSoftInputMode="adjustPan|stateHidden"

到在你的清单您的活动宣言。

+0

使用adjustPan屏幕不会调整大小。键盘停留在布局顶部,因此布局不会重叠,但也不会滚动。 – juancamilo87

+0

可以请你详细说明你的问题..!你想要什么? – Andrain

+0

我真正想要的是布局调整到一个最小高度,没有任何东西重叠,并成为可滚动。但读了很多后,我不认为这是可能的。所以我希望它可以滚动以避免我在图像上显示的重叠。 – juancamilo87

0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:animateLayoutChanges="true" 
    android:background="@android:color/darker_gray" 
    android:hapticFeedbackEnabled="true" > 

    <EditText 
     android:id="@+id/etName" 
     android:layout_width="60dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="10dp" 
     android:layout_marginTop="10dp" 
     android:gravity="center" /> 

    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/etName" 
     android:layout_centerInParent="true" 
     android:fillViewport="true" > 

     <LinearLayout 
      android:id="@+id/mLayout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:orientation="vertical" > 

      <Button 
       android:id="@+id/btn_newMatch" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="10dp" 
       android:text="New Match" 
       android:typeface="monospace" /> 

      <Button 
       android:id="@+id/btn_manageMatches" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="10dp" 
       android:text="Manage Matches" 
       android:typeface="monospace" /> 

      <Button 
       android:id="@+id/btn_manageTeams" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="10dp" 
       android:text="Manage Teams" 
       android:typeface="monospace" /> 

      <Button 
       android:id="@+id/btn_settings" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="10dp" 
       android:text="Settings" 
       android:typeface="monospace" /> 

      <Button 
       android:id="@+id/btn_logout" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Logout" 
       android:typeface="monospace" /> 
     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 

在活动代码,您的清单

android:windowSoftInputMode="adjustResize|stateHidden" 
+0

我已经尝试过,但不滚动。 :/ – juancamilo87

0

要防止的观点在垂直重叠我RelativeLayout当键盘被显示 - 只需添加边缘解决了这个问题

android:layout_marginTop="25dp"