5

मैं अपने Android एप्लिकेशन में बल्कि एक सरल प्रवेश पृष्ठ एक शीर्षक, उपयोगकर्ता नाम TextView, पासवर्ड TextView, लॉग इन बटन और एक छवि पाद लेख युक्तएंड्रॉइड के यूआई में बदलाव से कैसे बचें, जब कीबोर्ड चालू हो या अभिविन्यास बदल जाए?

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" > 

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#ffffff" > 

    <!-- Header Starts --> 

    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     > 

     <!-- Logo Start --> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dip" 
      android:src="@drawable/header" /> 
     <!-- Logo Ends --> 
    </LinearLayout> 

    <!-- Header Ends --> 

    <!-- Footer Start --> 
    <LinearLayout android:id="@+id/footer" 
    android:layout_width="fill_parent" 
    android:layout_height="90dip" 
    android:layout_alignParentBottom="true" 
    android:gravity="center"> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dip" 
      android:src="@drawable/footer" /> 
    </LinearLayout> 
    <!-- Footer Ends --> 

    <!-- Login Form --> 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="10dip" 
     android:layout_below="@+id/header" 
     > 

     <!-- Application Name Label --> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/app_name" 
      android:gravity="center" 
      android:padding="10dip" 
      android:textSize="25dp" 
      android:textStyle="bold" 
     /> 

     <!-- Username Label --> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="User Name" 
      android:textColor="#372c24" /> 

     <EditText 
      android:id="@+id/username" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dip" 
      android:layout_marginTop="5dip" 
      android:singleLine="true" /> 
     <!-- Password Label --> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Password" 
      android:textColor="#372c24" /> 

     <EditText 
      android:id="@+id/password" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dip" 
      android:layout_marginTop="5dip" 
      android:password="true" 
      android:singleLine="true" /> 
     <!-- Login button --> 

     <Button 
      android:id="@+id/btnLogin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dip" 
      android:text="Logon" /> 
     </LinearLayout> 
     <!-- Login Form Ends --> 

    </RelativeLayout> 
</ScrollView> 

मैं दो समस्याएं हैं मैं से संबंधित हैं लगता है:

  1. जब कीबोर्ड चालू होता है, और मैं नीचे स्क्रॉल करता हूं, तो मुझे लगता है कि छवि फूटर इसके नीचे रहने के बजाय लॉगिन बटन के पीछे "छिपा" है।
  2. वही तब हो रहा है जब स्क्रीन क्षैतिज रूप से उन्मुख हो।

बातें मैं कोशिश की है: गतिविधि android:windowSoftInputMode="adjustPan" में

  1. सेटिंग, लेकिन मैं जब कीबोर्ड दिखाई नीचे स्क्रॉल करने में सक्षम होना चाहते हैं, या android:windowSoftInputMode="adjustResize", या उस बात के लिए किसी अन्य परम।
  2. बटन में marginBottom सेट करना।

न तो काम किया। मैं किसी भी मदद की सराहना करता हूं।

उत्तर

1

मैं RelativeLayout क्षमताओं का उपयोग करके इस को हल करने समाप्त हो गया: मैं "लॉगिन प्रपत्र" "प्रपत्र" नाम की LinearLayout को एक आईडी जोड़ा, और imageView कि बटन के पीछे छिपा हुआ था को यह लाइन जोड़ा : एंड्रॉइड: layout_below = "@ + id/form"। फिर कुछ कॉस्मेटिक बदलाव किए। नीचे पूरा कोड:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:fillViewport="true" > 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#ffffff" > 

    <!-- Header Starts --> 
    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center"> 

     <!-- Logo Start --> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dip" 
      android:src="@drawable/header" /> 
     <!-- Logo Ends --> 

    </LinearLayout> 
    <!-- Header Ends --> 

    <!-- Login Form --> 
    <LinearLayout 
     android:id="@+id/form" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="10dip" 
     android:layout_below="@+id/header"> 

     <!-- Application Name Label --> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/app_name" 
      android:gravity="center" 
      android:padding="10dip" 
      android:textSize="25dp" 
      android:textStyle="bold"/> 

     <!-- Username Label --> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="User Name" 
      android:textColor="#372c24" /> 

     <EditText 
      android:id="@+id/username" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dip" 
      android:layout_marginTop="5dip" 
      android:singleLine="true" /> 

     <!-- Password Label --> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Password" 
      android:textColor="#372c24" /> 

     <EditText 
      android:id="@+id/password" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dip" 
      android:layout_marginTop="5dip" 
      android:password="true" 
      android:singleLine="true" /> 

     <!-- Login button --> 
     <Button 
      android:id="@+id/btnLogin" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dip" 
      android:text="Logon" /> 
    </LinearLayout> 
    <!-- Login Form Ends --> 

    <!-- Footer Start --> 
    <LinearLayout android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="90dip" 
     android:layout_alignParentBottom="true" 
     android:gravity="bottom|center" 
     android:paddingBottom="10dip" 
     android:layout_below="@+id/form" 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dip" 
      android:src="@drawable/footer" /> 

     </LinearLayout> 
     <!-- Footer Ends --> 

    </RelativeLayout> 

</ScrollView> 

धन्यवाद।

1

अपनी manifest.xml फ़ाइल खोलें। अपने गतिविधि टैब में बदलें।

<activity 
      android:configChanges="keyboardHidden|orientation" 
      android:name=".testActivity" 
      android:label="@string/app_name"></activity> 
+1

क्या आपका मतलब यह भी था कि मुझे कॉन्फ़िगरेशन चेंज विधि में कुछ लिखना चाहिए? क्योंकि मुझे नहीं पता कि कॉन्फ़िगरेशन कब बदला जाता है .. और केवल आपके सुझाव को लिखना काम नहीं करता है ... धन्यवाद – MichalK

0
<activity 
      android:configChanges="adjustPan" 
      android:name=".testActivity" 
      android:label="@string/app_name"></activity> 

"एंड्रॉइड: windowSoftInputMode" के बारे में देखें। उपलब्ध मोड here