2012-03-13 3 views
62

जब भी मैं इस गतिविधि को शुरू करता हूं, यह हमेशा नीचे शुरू होता है - नीचे तक सभी तरह से स्क्रॉल किया जाता है। मैं OnCreate (या उस मामले के लिए कहीं भी) गतिविधि में अजीब कुछ भी नहीं कर रहा हूं कि मैं स्क्रॉल स्थिति बदलने की उम्मीद करता हूं। मैंने शीर्ष फोकस करने योग्य नियंत्रण, और स्क्रोलो विधि पर ध्यान केंद्रित करने का प्रयास किया है, लेकिन उनमें से कोई भी काम नहीं कर रहा है। इसके अलावा, मेरी किसी अन्य गतिविधि में कोई समस्या नहीं है। यहाँ लेआउट है:मेरी एंड्रॉइड गतिविधि हमेशा नीचे स्क्रॉल क्यों शुरू होती है?

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scroll" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/edit_refresh_update_header" 
      android:textSize="18sp"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="\n" 
      android:textSize="4sp"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Variable:" 
      android:textSize="18sp"/> 

     <Spinner 
      android:id="@+id/edit_refresh_variables_spinner" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="\n" 
      android:textSize="4sp"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Network:" 
      android:textSize="18sp"/> 

     <RadioGroup 
      android:id="@+id/widget1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical"> 

      <RadioButton 
       android:text="Web" 
       android:id="@+id/edit_refresh_update_rb_web" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="NetRadioButtonSelected" 
       android:checked="true"/> 

      <RadioButton 
       android:text="Socket Server" 
       android:id="@+id/edit_refresh_update_rb_socket_server" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="NetRadioButtonSelected"/> 
     </RadioGroup> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="\n" 
      android:textSize="4sp"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Socket server request type:" 
      android:textSize="18sp"/> 

     <Spinner 
      android:id="@+id/edit_refresh_socket_server_req_types_spinner" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="\n" 
      android:textSize="4sp"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Socket server body:" 
      android:textSize="18sp"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:id="@+id/edit_refresh_update_ss_body" 
      android:layout_height="wrap_content" 
      android:enabled="false"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="\n" 
      android:textSize="4sp"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Url:" 
      android:textSize="18sp"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:id="@+id/edit_refresh_update_url" 
      android:layout_height="wrap_content"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="\n" 
      android:textSize="4sp"/> 

     <Button 
      android:text="Save refresh update" 
      android:id="@+id/edit_refresh_save_btn" 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:layout_marginLeft="20dip" 
      android:layout_marginRight="20dip" 
      android:layout_marginBottom="20dp" 
      android:layout_alignParentBottom="true" 
      android:onClick="SaveRefreshUpdate"> 
     </Button> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="\n" 
      android:textSize="4sp"/> 
    </LinearLayout> 
</ScrollView> 
+0

आपने फोकस को बदलने का प्रयास कैसे किया? –

+1

नीचे वर्णित फुलस्क्रॉल विधि का उपयोग करके और नीचे वर्णित स्क्रोलो विधि का उपयोग करके। मुझे जरूरी नहीं है कि इसे इस तरह से ठीक किया जाए, लेकिन ऐसा एक कारण होना चाहिए कि यह ऐसा क्यों शुरू हो रहा है और मैं इसे ठीक करके इसे ठीक करना चाहता हूं। – MrGibbage

उत्तर

236

जब एंड्रॉयड एक गतिविधि शुरू होता है, कुछ नियंत्रण:

+0

मेरे ग्रिडलाउट में काम नहीं कर रहा है। मेरे पास लेआउट के बीच में ग्रिड व्यू है, और यह हर बार ध्यान केंद्रित करता है। – Iqbal

+0

यह 'फोकस करने योग्य = सत्य' के साथ क्यों काम नहीं करता है? –

+0

पूरे दिन मेरे सिर को खरोंच कर लिया और यह नहीं पता कि यह केवल एक विशेष गतिविधि में क्यों हो रहा था और मुझे अभी भी समझ में नहीं आया क्योंकि मैंने किसी भी दृश्य पर ध्यान केंद्रित नहीं किया है। लेकिन धन्यवाद, मैं इस मुद्दे को ठीक करने में कामयाब रहा। यह बहुत अच्छा होगा अगर कोई कुछ प्रकाश डाल सके क्योंकि संभावित कारण क्या हो सकता है क्योंकि नई गतिविधि में कुछ नया नहीं है। – Shubhral

0

मैं पता नहीं क्यों, लेकिन आप अपने onCreate में

ScrollView sv = (ScrollView) findViewById(R.id.scroll); 
sv.scrollTo(0,0); 

के साथ प्रयोग मैन्युअल जहां आप इसे होना चाहते करने के लिए यह स्क्रॉल करने के लिए कर सकता है। ? //developer.android.com/reference/android/widget/ScrollView.html#fullScroll (int)

yourScrollView.fullScroll(ScrollView.FOCUS_UP); 
+0

यह वही है जिस तरह मैंने कोशिश की, लेकिन यह काम नहीं किया। – MrGibbage

1

आप उपयोग fullScroll विधि http करने की कोशिश की है ध्यान केंद्रित करने की जरूरत है। जब फोकस करने के लिए कोई नामित नियंत्रण नहीं होता है, तो सिस्टम पहले पात्र नियंत्रण को चुनता है जो फोकस चाहता है। यदि आप अपने LinearLayout में निम्नलिखित संपत्ति सेट करते हैं - android:focusableInTouchMode="true" आपके LinearLayout को प्रारंभ पर केंद्रित किया जाएगा और आपकी गतिविधि नीचे EditText पर स्क्रॉल नहीं होगी।

+1

ने कोशिश की। यह काम नहीं किया। – MrGibbage

2

आप इस कोड की कोशिश कर सकते हैं:

scroller.post(new Runnable() { 
    public void run() { 
     scroller.fullScroll(ScrollView.FOCUS_DOWN); 
    } 
}); 

[एन: बी] [सन्दर्भ कड़ी] 1

+1

यह एक अच्छा विकल्प है, लेकिन यह एक अच्छा उपयोगकर्ता अनुभव नहीं खोलने के बाद एक झटका अनुकरण करता है, मुझे लगता है कि – iBabur

1

क्या devmiles.com कहा के साथ।

आप अपने LinearLayout में निम्नलिखित गुण सेट है - एंड्रॉयड: focusableInTouchMode = "true" अपने LinearLayout शुरू करने पर ध्यान केंद्रित किया जाएगा और अपनी गतिविधि तल में EditText के लिए स्क्रॉल नहीं होंगे।

यदि आप अपने रैखिक लेआउट के तल पर एक दृश्य पर requestLayout() फोन इसे अपने शीर्ष सबसे देखने से ध्यान केंद्रित चोरी हो सकता है। तो निचले दृश्य पर requestLayout() को कॉल करने के बाद रैखिक लेआउट में शीर्ष दृश्य पर अनुरोध अनुरोध फोकस() पर कॉल करें।

22
इसके बजाय अपने लेआउट में आइटम प्रदूषण की

, आप अपनी गतिविधि/क्लास में इस जोड़ सकते हैं:

ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView); 
    scrollView.setFocusableInTouchMode(true); 
    scrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); 

इस तरह यह अपने scrollview हो रही फोकस के भीतर एक तत्व नहीं है, यह एक कंटेनर के रूप में अपने scrollview है जो इसके बाद बच्चे के दृश्य पर आगे बढ़ने वाला पहला फोकस प्राप्त करें।

+0

धन्यवाद, यह मेरे लिए काम करने वाला एकमात्र ऐसा था जो – commonSenseCode

+0

स्क्रॉलव्यू –

+0

के अंदर बच्चों के आधार पर ListView ऊंचाई सेट करने का प्रयास करते समय आंशिक रूप से मेरे लिए काम करता है मदद की! (जबकि एक्सएमएल में एक ही विशेषता काम नहीं किया ..) –

0

Xamarin Android विकास के लिए, यदि आप तो @Graeme समाधान करना चाहते हैं:

// Set Focus to ScrollView 
ScrollView scrollView = (ScrollView)FindViewById(Resource.Id.scrollView); 
scrollView.FocusableInTouchMode = true; 
scrollView.DescendantFocusability = Android.Views.DescendantFocusability.BeforeDescendants; 
0

बस इसे onCreate()

editText.setFocusable(false); 

में फ़ोकस करने योग्य नहीं बनाने के लिए और का उपयोग

editText.setOnClickListener(new ....){ 
...... 
    editText.setFocusable(true); 
    editText.setFocusableInTouchMode(true); 
    editText.requestFocus(); 

    showSoftKeyboard(); //Use InputMethodManager to open soft Keyboard 

...... 
}; 

और यह अगली बार Edittext तक स्क्रॉल नहीं करेगा, एक टुकड़ा या गतिविधि बनाई गई है।