2013-10-02 3 views
1

Я сделал макет. Когда я начинаю вводить учетные данные для входа, появляется клавиатура, и теперь я не могу прокручивать ее, чтобы заполнить другие данные. Таким образом, все взгляды скрываются за клавиатурой. Пожалуйста, помогите мне исправить это так, что когда клавиатура открыта, то она должна начать прокручивание, чтобы увидеть другие взглядыПрокрутка Не работает, когда клавиатура открыта в android

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/login_bg" > 

    <RelativeLayout 
     android:id="@+id/top_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:onClick="hideKeyboard" > 

     <ImageView 
      android:id="@+id/top_header" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/blank_header" 
      android:scaleType="fitXY" /> 

     <ImageView 
      android:id="@+id/top_header" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:scaleType="fitXY" 
      android:src="@drawable/login_font" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:onClick="hideKeyboard" > 

     <Utility.LoginRL 
      android:id="@+id/scrollview" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="85dp" 
      android:onClick="hideKeyboard" 
      android:scrollbars="none" > 

      <RelativeLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

       <ImageView 
        android:id="@+id/logo" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="10dp" 
        android:onClick="hideKeyboard" 
        android:paddingBottom="15dp" 
        android:src="@drawable/logo" /> 

       <RelativeLayout 
        android:id="@+id/user_pass_layout" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/logo" 
        android:layout_centerHorizontal="true" 
        android:layout_margin="5dip"> 

        <LinearLayout 
         android:id="@+id/username_layout" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:background="@drawable/user_text1" 
         android:gravity="center_vertical" 
         android:onClick="showKeyboard" 
         android:paddingBottom="20dp" > 

         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginTop="5dp" 
          android:paddingLeft="10dp" 
          android:text="User Name" 
          android:textColor="#9D9D9D" 
          android:textSize="20dp" /> 

         <EditText 
          android:id="@+id/uName" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginTop="5dp" 
          android:background="#00000000" 
          android:paddingLeft="10dp" 
          android:singleLine="true" 
          android:text="" 
          android:textColor="#228ED3" 
          android:textSize="20dp" /> 
        </LinearLayout> 

        <LinearLayout 
         android:id="@+id/password_layout" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_below="@id/username_layout" 
         android:background="@drawable/user_text2" 
         android:gravity="center_vertical" 
         android:onClick="showKeyboard" 
         android:layout_margin="5dip" 
         android:paddingBottom="10dp" > 

         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginTop="5dp" 
          android:onClick="showKeyboard" 
          android:paddingLeft="10dp" 
          android:paddingRight="5dp" 
          android:text="Password" 
          android:textColor="#9D9D9D" 
          android:textSize="20dp" /> 

         <EditText 
          android:id="@+id/pass" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginTop="5dp" 
          android:background="#00000000" 
          android:paddingLeft="10dp" 
          android:password="true" 
          android:singleLine="true" 
          android:text="" 
          android:textColor="#228ED3" 
          android:textSize="20dp" /> 
        </LinearLayout> 
       </RelativeLayout> 

       <!-- 
      <LinearLayout 
      android:id="@+id/site_url_layout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/user_pass_layout" 
      android:layout_centerHorizontal="true" 
      android:paddingBottom="10dp" 
      android:paddingTop="20dp" > 



       --> 

       <TextView 
        android:id="@+id/lbl_siteUrl" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/user_pass_layout" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="10dp" 
        android:background="@drawable/site_url1" 
        android:gravity="center_vertical" 
        android:onClick="showKeyboard" 
        android:paddingLeft="10dp" 
        android:layout_margin="5dip" 
        android:paddingTop="10dp" 
        android:text="Site Url" 
        android:textColor="#9D9D9D" 
        android:textSize="20dp" /> 

       <EditText 
        android:id="@+id/siteUrl" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/lbl_siteUrl" 
        android:layout_centerHorizontal="true" 
        android:background="@drawable/site_url2" 
        android:gravity="top" 
        android:paddingLeft="10dp" 
        android:singleLine="true" 
        android:text="http://" 
        android:textColor="#228ED3" 
        android:textSize="20dp" /> 
       <!-- </LinearLayout> --> 

       <ImageView 
        android:id="@+id/login_btn" 
        android:layout_width="wrap_content" 
        android:layout_margin="5dip" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/siteUrl" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="20dp" 
        android:paddingBottom="10dp" 
        android:src="@drawable/login_btn" /> 

       <ImageView 
        android:id="@+id/forgot_pass_btn" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/login_btn" 
        android:layout_centerHorizontal="true" 
        android:src="@drawable/forgot_pass_btn" /> 
      </RelativeLayout> 
     </Utility.LoginRL> 
    </RelativeLayout> 

</RelativeLayout> 

LoginRL

общественного класса LoginRL расширяет Scrollview { общественное логическое isKeyboardHidden = истина;

public LoginRL(Context context) { 
     super(context); 
    } 

    public LoginRL(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public LoginRL(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
     final int proposedheight = MeasureSpec.getSize(heightMeasureSpec); 
     final int actualHeight = getHeight(); 

     if (actualHeight > proposedheight){ 
      isKeyboardHidden = false; 
      //LoginScreen.keyboardToolbar.setVisibility(View.VISIBLE); 
     } else { 
      isKeyboardHidden = true; 
      //LoginScreen.keyboardToolbar.setVisibility(View.GONE); 
     } 
    } 

} 

ответ

0

Используйте это:

InputMethodManager inputManager = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
+0

Что такое v здесь? –

+0

V будет вашим родительским представлением. Это может быть ваш корневой макет. –

+0

Ты не понял мой вопрос. Пожалуйста, прочитайте снова ... Когда клавиатура открывается, макет должен двигаться вверх, и она должна начинаться с прокрутки. –

0

Оберните расположение внутри ScrollView, и вы будете иметь возможность прокрутки, когда клавиатура отображается.

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

    <RelativeLayout 
     android:id="@+id/top_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:onClick="hideKeyboard" > 

    ....... 

</ScrollView> 
+0

Я пробовал, но все еще не прокручиваю, когда открыта клавиатура. Боттом взгляды скрываются за клавиатурой –

Смежные вопросы