簡體   English   中英

鍵盤出現時如何使android視圖可滾動?

[英]how to make an android view scrollable when the keyboard appears?

我有一些視圖(名稱,電子郵件,密碼,注冊按鈕):

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ViewFlipper
        android:id="@+id/viewflipper"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        //Layouts

    </ViewFlipper>

</ScrollView>

當我關注edittext字段時,鍵盤出現並覆蓋視圖上的下部字段。 所以當鍵盤存在時我看不到它們。 我想知道如何使視圖可滾動,以便我可以看到較低的字段。 此外,如何使視圖自動滾動以使聚焦的字段可見。

您需要在AndroidManifest.xml文件中為您的活動包含android:windowSoftInputMode="adjustResize"屬性 - 然后Android應自動為您調整大小:

<activity android:name="..."
          ...
          android:windowSoftInputMode="adjustResize">
    ...
/>

我已經創建了簡單的xml文件,希望這是你正在尋找的。

第1步 你可以在鍵盤出現時滾動。

第2步 當你點擊Text-Field時,它會出現在Focus /上面的鍵盤上。

<ScrollView android:id="@+id/ScrollView01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true" 
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:weightSum="1.0" 
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true" 
    android:id="@+id/l_layout">
    <EditText 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:id="@+id/editText1" 
        android:layout_marginTop="100dp">
        <requestFocus></requestFocus>
    </EditText>
    <EditText 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:id="@+id/editText2" 
        android:layout_marginTop="100dp">
        </EditText>
    </LinearLayout> 
</ScrollView>

你試過這個:

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ViewFlipper
    android:id="@+id/viewflipper"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/scroll_container">
        //Layouts
    </ScrollView>


</ViewFlipper>

在我的情況下@Aleks G解決方案無法正常工作。 所以我解決了我的問題

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/registration_scroll_view"
    android:layout_alignParentTop="true"
    android:layout_above="@+id/btn_register_submit"
    >

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

       <!--This comment will be replaced 
           by your focusable views-->

    </LinearLayout>
</ScrollView>

<Button
    android:id="@+id/btn_register_submit"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/form_action_button_green"
    android:gravity="center"
    android:text="@string/submit"
    />

</RelativeLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM