2017-10-19 172 views
-2

我試圖製作一個UI,屏幕中間有幾個字段,底部有一個按鈕。當我在字段中寫入數字時,鍵盤隱藏了界面的一部分(我希望它),但是我還需要整個界面可滾動,以便我可以調整屏幕並使用鍵盤填充字段上。我把整個設置放在一個相對的佈局中,並放在滾動視圖下。這裏的帖子說它應該這樣工作,但它不適合我。滾動視圖內部的相對佈局不可滾動

的XML代碼是

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.maaz.rakattracker.MainActivity"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 


     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:orientation="horizontal"> 

       <EditText 
        android:id="@+id/farzET" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:ems="10" 
        android:gravity="center" 
        android:hint="0" 
        android:inputType="number" 
        android:singleLine="true" 
        android:textAlignment="center" /> 

       <TextView 
        android:id="@+id/farzLbl" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:elevation="0dp" 
        android:ems="5" 
        android:text="farz" 
        android:textAlignment="center" 
        android:textSize="15sp" /> 

      </LinearLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:orientation="horizontal"> 

       <EditText 
        android:id="@+id/sunnatET" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:ems="10" 
        android:hint="0" 
        android:inputType="number" 
        android:singleLine="true" 
        android:textAlignment="center" /> 

       <TextView 
        android:id="@+id/sunnatLbl" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:ems="5" 
        android:text="Sunnat" 
        android:textAlignment="center" 
        android:textSize="15sp" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:orientation="horizontal"> 

       <EditText 
        android:id="@+id/naflET" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:ems="10" 
        android:gravity="center" 
        android:hint="0" 
        android:inputType="number" 
        android:singleLine="true" 
        android:textAlignment="center" /> 

       <TextView 
        android:id="@+id/naflLbl" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:ems="5" 
        android:text="Nafl" 
        android:textAlignment="center" 
        android:textSize="15sp" /> 

      </LinearLayout> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:orientation="horizontal"> 

       <EditText 
        android:id="@+id/witrET" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:ems="10" 
        android:hint="0" 
        android:inputType="number" 
        android:singleLine="true" 
        android:textAlignment="center" /> 

       <TextView 
        android:id="@+id/witrLbl" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:ems="5" 
        android:text="Witr" 
        android:textAlignment="center" 
        android:textSize="15sp" /> 
      </LinearLayout> 
     </LinearLayout> 

     <Button 
      android:id="@+id/startButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" 
      android:text="Button" /> 
    </RelativeLayout> 
</ScrollView> 

請幫我在這裏找出問題。 感謝

+0

你是什麼targetSdkVersion? – Thracian

回答

0

嘗試在你的活動添加里面的onCreate代碼()方法:

getWindow()setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_PAN)。

+0

那就是。我應該刪除滾動視圖,如果該模式啓用? –

0

在您的清單中,將android:windowSoftInputMode="adjustResize"添加到您的活動標籤。

0

在您的清單文件中添加

<activity 
     android:name=".YOURACTIVITY" 
     android:windowSoftInputMode="adjustPan" /> 
    <activity 
+0

那就是。我是否需要移除滾動視圖並使其保持簡單? –

0

,由於滾動視圖只能與LinearLayout中工作

+0

我閱讀了這個作品的多個職位 –

+0

沒有不幸的是你不能做到這一點。 嘗試把你的相對佈局內線性佈局,它會工作 –

+0

請參閱滾動android api: [鏈接](https://developer.android.com/reference/android/widget/ScrollView.html) 和一些技術見: [鏈接](https://material.io/guidelines/patterns/scrolling-techniques.html#scrolling-techniques-behavior) –