2011-03-15 11 views
18

मेरे पास edittext के साथ एक विशिष्ट listview है और गतिविधि के नीचे एक बटन है।पृष्ठभूमि छवि का आकार बदलने से सॉफ्ट कीबोर्ड को कैसे रोकें

जब मैं edittext पर क्लिक करता हूं, तो सॉफ्ट कीबोर्ड दिखाई देता है, मैं listview में आइटम स्क्रॉल करने में सक्षम हूं लेकिन यह मेरी पृष्ठभूमि छवि को दोबारा आकार देता है।

मैंने android:windowSoftInputMode="adjustResize" को आजमाया है लेकिन कोई फर्क नहीं पड़ता।

मैंने android:windowSoftInputMode="adjustPan" को आजमाया है। छवि squashed नहीं मिलता है, पूरा लेआउट ऊपर की ओर बढ़ता है और मैं शीर्षक पट्टी खो देता है। यदि सूची आइटम लेआउट आकार से अधिक हो तो मैं केवल सूची स्क्रॉल कर सकता हूं।

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

उत्तर

3

मुलायम कीबोर्ड को पृष्ठभूमि छवि का आकार बदलने से रोकने का कोई तरीका नहीं है।

इस scaleType(matrix) का उपयोग करें और एक उपयुक्त छवि तैयार करें।

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/RelativeLayoutchat" 
    > 

    <LinearLayout 
    android:orientation="horizontal" 
    android:gravity ="clip_horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_centerInParent="true"> 

    <ImageView 
     android:gravity ="clip_horizontal" 
     android:id="@+id/chat_bak_img" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="matrix"> 
    </ImageView> 

    </LinearLayout> 

    <LinearLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <ListView 
     android:id="@+id/chat" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:transcriptMode="alwaysScroll" 
     android:divider="#000000" 
     android:clickable="false" 
     android:layout_weight="9" 
     android:cacheColorHint="#00000000"/> 



    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_weight="1" 
     style="@android:style/ButtonBar" 
     android:gravity="center" 
     android:paddingLeft="3dip" 
     android:paddingTop="3dip" 
     android:paddingRight="3dip"> 
     <EditText 
      android:id="@+id/chatMsg" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:maxLines="5" 
      android:enabled="true" 
      android:textSize="17sp" 
      android:maxLength="150"/> 
     <Button 
      android:id="@+id/sendMsg" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="@string/send_withSpace" 
      android:layout_weight="4"/> 
    </LinearLayout> 

    </LinearLayout> 

</RelativeLayout> 
+0

एहम, मुझे लगता है कि समायोजन आमतौर पर बीजी को आकार बदलने से रोकता है। – Ted

37

सूचीदृश्य के लिए आप

android:isScrollContainer="false" 

का उपयोग करें और

android:windowSoftInputMode="adjustPan" 
+6

मेरे लिए काम नहीं किया। – mschonaker

+1

मेनी समाधानों ने कोशिश की, अंत में स्क्रॉल-व्यू के लिए यह काम किया। बहुत बहुत धन्यवाद। –

9

AndroidManifest.xml पर जाएं और Manifest.xml में अपनी गतिविधि को यह जोड़ने की जरूरत:

activity name="activityname" android:windowSoftInputMode="stateVisible|adjustPan" 
+1

लेकिन यह बीजी छवि का आकार बदलता है –

19

मैंने कोशिश की है कि हलवी के लिए समाधान हो सकते हैं इस समस्या को एनजी। एंड्रॉइड: windowSoftInputMode = "adjustPan" कुंजीपटल के साथ आपकी पूरी स्क्रीन शिफ्ट कर देगा। आम तौर पर हमारे पास शीर्ष पर स्क्रीन का शीर्षक होता है। इस ध्वज का उपयोग करके यह दृश्य क्षेत्र से भी बाहर निकल जाएगा, जो खराब उपयोगकर्ता अनुभव बनाता है। मैं android:windowSoftInputMode="adjustResize" का उपयोग करता हूं यह पूरी स्क्रीन का आकार बदल देगा लेकिन यह प्रश्न में एक ही समस्या @ मॉरीस राज्य का कारण बन जाएगा।

तो यहाँ मेरा अंतिम समाधान है:

प्रकट

android:windowSoftInputMode="adjustResize|stateAlwaysHidden" 

एक्सएमएल में

न सेट किसी भी पृष्ठभूमि में यहाँ scrollview

तहत

आपके विचार रखने के जावा में

आप विंडो को पृष्ठभूमि निर्धारित करने की आवश्यकता:

getWindow().setBackgroundDrawableResource(R.drawable.bg_wood) ; 
+2

+1 यदि आप अपने तत्वों का आकार बदलना चाहते हैं, तो यह सही जवाब है, जबकि आपकी पृष्ठभूमि उतनी ही रहती है। यह उत्तर अधिक ध्यान देने योग्य है। – Levit

+1

बहुत बढ़िया! अच्छा उत्तर! – gonzalomelov

+0

भयानक उत्तर, इनके माध्यम से समाधान मिला .. –

1

मैं imageView के साथ एक ही समस्या है आकार बदलने जबकि ऊपर कुंजीपटल मैं प्रकट एंड्रॉयड के साथ हल किया है: windowSoftInputMode = "adjustPan" और निम्नलिखित लेआउट उदाहरण है मेरे मामले में

i।ई frg_write_social:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/frg_writeyourpost_ll_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true" 
android:fitsSystemWindows="true" 
android:isScrollContainer="false" 
android:scrollbars="none" > 

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

    <RelativeLayout 
     android:id="@+id/frg_writeyourpost_rl_top" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/frg_writeyourpost_ll_bottum" 
     android:layout_alignParentTop="true" 
     android:minHeight="400dip" > 

     <ImageView 
      android:id="@+id/frg_writyourpost_iv" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_centerInParent="true" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" /> 
    </RelativeLayout> 

    <LinearLayout 
     android:id="@+id/frg_writeyourpost_ll_bottum" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="vertical" 
     android:padding="10dp" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_marginTop="10dp" 
      android:background="@android:color/white" 
      android:gravity="center" 
      android:orientation="vertical" 
      android:padding="10dp" > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:gravity="center" 
       android:text="Write your post" 
       android:textColor="#727F8D" 
       android:textSize="10sp" /> 

      <com.example.views.CustomEditText 
       android:id="@+id/frg_writeyourpost_et_message" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/slide_image" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:background="@null" 
       android:inputType="textMultiLine" 
       android:maxHeight="@dimen/slide_image" 
       android:maxLines="3" 
       android:textSize="11sp" > 
      </com.example.views.CustomEditText> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:orientation="horizontal" > 

       <TextView 
         android:id="@+id/frg_writeyourpost_tv_totalcharacter" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:text="0" 
        android:textColor="#727F8D" 
        android:textSize="8sp" /> 

       <TextView 
       android:id="@+id/frg_writeyourpost_tv_characterLeft" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="5dp" 
        android:gravity="center" 
        android:text="character" 
        android:textColor="#727F8D" 
        android:textSize="8sp" /> 
      </LinearLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:orientation="horizontal" > 

      <RadioGroup 
       android:id="@+id/frg_writepost_fbtw_rggroup" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" > 

       <RadioButton 
        android:id="@+id/frg_writepost_rb_facebook" 
        android:layout_width="0dip" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:background="@drawable/fb_check_selector" 
        android:button="@android:color/transparent" 
        android:gravity="center" 
        android:padding="10dip" 
        android:text="@string/post_for_facebook"/> 

       <View 
        android:layout_width="5dip" 
        android:layout_height="match_parent" 
        android:background="@android:color/transparent"/> 

       <RadioButton 
        android:id="@+id/frg_writepost_rb_twitter" 
        android:layout_width="0dip" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:background="@drawable/tw_check_selector" 
        android:button="@android:color/transparent" 
        android:gravity="center" 
        android:padding="10dip" 
        android:text="@string/post_for_twitter"/> 
      </RadioGroup> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

अगर वहाँ संभव है छवि को लोड करने गतिशील आप fill_parent साथ imageView

1

उपयोग imageView में लोड और centerCrop RelativeLayout में जिम्मेदार बताते हैं, जबकि picaaso साथ छवि का आकार कर सकते हैं। इस कदर;

<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="match_parent" 
    > 
    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:src="@drawable/yazisma_arka_plan" 
     android:scaleType="centerCrop" 
     /> 
    <ListView 
     android:id="@+id/messages_view" 
     android:layout_width="fill_parent"... 
3

android:windowSoftInputMode="adjustResize" और बस का उपयोग एक scrollview में अपनी पृष्ठभूमि imageView लपेट दें।

<ScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scrollbars="none" 
    android:overScrollMode="never"> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</ScrollView> 
+0

Softlion

0

एर, मुझे देखने दो ... पहले चित्र!

View before touched View after touched लेआउट फ़ाइल act_login.xml।

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/login_bkgd" 
    android:orientation="vertical" 
    android:paddingLeft="25dp" 
    android:paddingRight="25dp" 
    > 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:cacheColorHint="#0fff" 
     android:scrollbars="none" 
     android:listSelector="#0fff" 
     android:divider="#0fff" 
     android:dividerHeight="0dp" 
     android:isScrollContainer="true" 
     /> 
    <!--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!--> 
    <!--android:isScrollContainer="true"--> 
    <!--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!--> 

    <LinearLayout 
     android:id="@+id/loginItem" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     > 

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

      <ImageView 
       android:id="@+id/loginLogo" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="35dp" 
       android:layout_marginTop="35dp" 
       android:scaleType="fitCenter" 
       android:src="@drawable/logo" 
       /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:paddingBottom="35dp" 
       > 

       <View 
        android:layout_width="0dp" 
        android:layout_height="1px" 
        android:layout_weight="1" 
        android:background="#Ffff" 
        /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="6dp" 
        android:layout_marginRight="6dp" 
        android:text="WELCOME" 
        android:textColor="#Ffff" 
        android:textSize="14sp" 
        /> 

       <View 
        android:layout_width="0dp" 
        android:layout_height="1px" 
        android:layout_weight="1" 
        android:background="#Ffff" 
        /> 
      </LinearLayout> 
     </LinearLayout> 

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

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:background="@drawable/login_et_long" 
       android:gravity="center" 
       android:paddingLeft="10dp" 
       android:paddingRight="10dp" 
       > 

       <TextView 
        android:layout_width="60dp" 
        android:layout_height="wrap_content" 
        android:background="@null" 
        android:text="账号:" 
        android:textColor="#Ffff" 
        android:textSize="16sp" 
        /> 

       <EditText 
        android:id="@+id/loginUsername" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:background="@null" 
        android:hint="请输入手机号" 
        android:imeOptions="actionNext" 
        android:inputType="text" 
        android:singleLine="true" 
        android:textColor="#F000" 
        android:textSize="16sp" 
        /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:layout_marginBottom="45dp" 
       android:layout_marginTop="10dp" 
       android:background="@drawable/login_et_long" 
       android:gravity="center" 
       android:paddingLeft="10dp" 
       android:paddingRight="10dp" 
       > 

       <TextView 
        android:layout_width="60dp" 
        android:layout_height="wrap_content" 
        android:background="@null" 
        android:text="密码:" 
        android:textColor="#Ffff" 
        android:textSize="16sp" 
        /> 

       <EditText 
        android:id="@+id/loginPassword" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:background="@null" 
        android:hint="请输入密码" 
        android:imeOptions="actionGo" 
        android:inputType="textPassword" 
        android:singleLine="true" 
        android:textColor="#F000" 
        android:textSize="16sp" 
        /> 
      </LinearLayout> 

      <TextView 
       android:id="@+id/login" 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:background="@drawable/login_button" 
       android:gravity="center" 
       android:padding="10dp" 
       android:text="@string/str_login" 
       android:textColor="#Ffff" 
       android:textSize="19sp" 
       /> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

संबंधित जावा कोड।

EditText etUsername, etPassword; 
EditText etFocus; 
ViewGroup base; 
int mSelection; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    base=(ViewGroup)getLayoutInflater().inflate(R.layout.act_login, null); 
    setContentView(base); 
    getWindow().setBackgroundDrawable(base.getBackground()); 
    base.setBackground(null); 
    super.onCreate(savedInstanceState); 
} 

@Override 
protected void initViews() { 
    etUsername=(EditText)findViewById(R.id.loginUsername); 
    etPassword=(EditText)findViewById(R.id.loginPassword); 

    final ViewGroup item=(ViewGroup)findViewById(R.id.loginItem); 
    base.removeView(item); 
    final View[] items=new View[item.getChildCount()]; 
    for(int i=0; i<item.getChildCount(); i++) items[i]=item.getChildAt(i); 
    item.removeAllViews(); 

    ListView lv=(ListView)base.getChildAt(0); 
    lv.setAdapter(new BaseAdapter() { 
    public View getView(int i, View v, ViewGroup vg) { 
     if(etFocus!=null && getCurrentFocus()!=etFocus){ 
      etFocus.requestFocus(); 
      etFocus.setSelection(mSelection); 
      //etFocus=null; 
     } 
     return items[i]; 
    } 
    public int getCount() {return items.length;} 
    public Object getItem(int position) {return null;} 
    public long getItemId(int position) {return 0;} 
    }); 

    /*View.OnTouchListener listener=new View.OnTouchListener() { 
     @Override 
     public boolean onTouch(View v, MotionEvent e) { 
      if(e.getAction()!=MotionEvent.ACTION_UP) return false; 
      etFocus=(EditText)v; 
      mSelection=etFocus.getSelectionEnd(); 
      ZZ.z("_________________ mSelection="+mSelection); 
      return false; 
     } 
    }; 
    etUsername.setOnTouchListener(listener); 
    etPassword.setOnTouchListener(listener);*/ 

    View.OnFocusChangeListener listener1=new View.OnFocusChangeListener() { 
     @Override 
     public void onFocusChange(View v, boolean hasFocus) { 
      if(!hasFocus){ 
       etFocus=(EditText)v; 
       mSelection=etFocus.getSelectionStart(); 
       ZZ.z("_________________ mSelection="+mSelection); 
      } 
     } 
    }; 
    etUsername.setOnFocusChangeListener(listener1); 
    etPassword.setOnFocusChangeListener(listener1); 
} 

AndroidManifest भाग।

<activity 
     android:name=".ui.activity.ActLogin" 
     android:label="@string/str_login" 
     android:theme="@style/myTheme" 
     /> 
    <!--android:windowSoftInputMode="adjustResize"--> 

शैली का हिस्सा।

<style name="myTheme" parent="@android:style/Theme.Light.NoTitleBar"> 
    <item name="android:windowTranslucentStatus">true</item> 
</style> 
0

मैं इतना अधिक जवाब का एक बहुत पढ़ा है और मेरे ऐप काम करता है बनाने के लिए कई से कुछ ले लिया:

  1. नहीं ScrollView बिल्कुल मेरी activity_main.xml
  2. AndroidManifest.xml में करने के लिए इस विशेषता को जोड़

    <activity android:name=".MainActivity"

,210

टैग:

`android:windowSoftInputMode="adjustResize"` 
  1. onCreate() मैं getWindow().setBackgroundDrawableResource(R.drawable.app_bg);

यह मेरे लिए काम करता है जब अन्य सभी पूरा जवाब मैं नहीं की कोशिश की है जोड़ा अंदर MainActivity.java में 'टी। यदि आप यहां तक ​​पहुंच गए हैं, तो मुझे उम्मीद है कि यह आपके लिए भी काम करेगा।

संबंधित मुद्दे