2012-03-23 11 views
6

मैं निम्नलिखित कोड का उपयोग कर मेरी TextView स्क्रॉल करने के लिए कोशिश कर रहा हूँ:TextView स्क्रॉल नहीं निर्बाध रूप

TextView text = (TextView) findViewById(R.id.textView12); 
     text.setMovementMethod(ScrollingMovementMethod.getInstance()); 
     int height = getResources().getDrawable(R.drawable.pic_ground_pranic).getIntrinsicHeight(); 
     text.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, height)); 
     text.setText("As part of an Android App I am building a button set.For performance reasons and to keep the code simpler, the Android system uses pixels as the standard unit for expressing dimension or coordinate values. That means that the dimensions of a view are always expressed in the code using pixels, but always based on the current screen density. For instance, if myView.getWidth() returns 10, the view is 10 pixels wide on the current screen, but on a device with a higher density screen, the value returned might be 15. If you use pixel values in your application code to work with bitmaps that are not pre-scaled for the current screen density, you might need to scale the pixel values that you use in your code If you need to control exactly how your application will look on various screen configurations, adjust your layouts and bitmap drawables in configuration-specific resource directories. For example, consider an icon that you want to display on medium and high density screens. Simply create your icon at two different sizes (for instance 100x100 for medium density and 150x150 for high density) and put the two variations in the appropriate directories, using the proper qualifiers: For instance, suppose a device has a WVGA high-density screen, which is 480x800 and about the same size as a traditional HVGA screen, but it's running an application that has disabled pre-scaling. In this case, the system will lie to the application when it queries for screen dimensions, and report 320x533 (the approximate mdpi translation for the screen density). Then, when the application does drawing operations, such as invalidating the rectangle from (10,10) to (100, 100), the system transforms the coordinates by scaling them the appropriate amount, and actually invalidate the region (15,15) to (150, 150). This discrepancy may cause unexpected behavior if your application directly manipulates the scaled bitmap, but this is considered a reasonable trade-off to keep the performance of applications as good as possible. If you encounter this situation, read Based on the density of the current screen, the system uses any size- or density-specific resources from your application and displays them without scaling. If resources are not available in the correct density, the system loads the default resources and scales them up or down as needed to match the current screen's density. The system assumes that default resources (those from a directory without configuration qualifiers) are designed for the baseline screen density (mdpi), unless they are loaded from a density-specific resource directory. Pre-scaling is, thus, what the system does when resizing a bitmap to the appropriate size for the current screen density. to match the un-scaled bitmap source. The buttons are part of a nested set of LinearLayouts.The question then is: How to resize the layout.I have tried several suggested techniques, and none come close to working. Here is a subset of the XML that builds the button set:"); 

सभी ठीक काम कर रहा है, लेकिन मेरे पाठ दृश्य को सुचारू रूप से स्क्रॉल नहीं है। मैंने सोचा कि मुझे अपना टेक्स्टव्यू स्क्रॉलव्यू के अंदर रखना है लेकिन यह भी काम नहीं कर रहा है।

ऐसा इसलिए होता है क्योंकि मैं अपना टेक्स्टव्यू बदल रहा हूं?

कृपया इस समस्या के लिए कोई समाधान प्रदान करें। मैंने इस पर बहुत समय बिताया है।

मेरे XML लेआउट फ़ाइल है:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/include1" 
     android:layout_centerHorizontal="true" 
     android:background="@android:color/white" 
     android:scrollbarStyle="insideInset" > 

     <TableLayout 
      android:id="@+id/tableLayout1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:padding="5dp" > 

      <TableRow 
       android:id="@+id/tableRow1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

       <RelativeLayout 
        android:id="@+id/relativeLayout2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1.0" > 

        <TextView 
         android:id="@+id/textView2" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentLeft="true" 
         android:layout_marginLeft="5dp" 
         android:layout_marginTop="14dp" 
         android:text="Text 1" 
         android:textColor="@android:color/black" /> 

        <TextView 
         android:id="@+id/textView3" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignBottom="@+id/textView2" 
         android:layout_marginLeft="25dp" 
         android:layout_toRightOf="@+id/textView2" 
         android:text="Text 2" 
         android:textColor="@android:color/black" /> 

        <TextView 
         android:id="@+id/textView4" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignBottom="@+id/textView3" 
         android:layout_marginLeft="25dp" 
         android:layout_toRightOf="@+id/textView3" 
         android:text="Text 3" 
         android:textColor="@android:color/black" /> 

        <TextView 
         android:id="@+id/textView5" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignTop="@+id/textView4" 
         android:layout_marginLeft="25dp" 
         android:layout_toRightOf="@+id/textView4" 
         android:text="Text 4" 
         android:textColor="@android:color/black" /> 

        <TextView 
         android:id="@+id/textView6" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentLeft="true" 
         android:layout_below="@+id/textView2" 
         android:layout_marginLeft="5dp" 
         android:layout_marginTop="3dp" 
         android:textColor="@android:color/black" /> 

        <TextView 
         android:id="@+id/textView7" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignLeft="@+id/textView3" 
         android:layout_below="@+id/textView3" 
         android:layout_marginTop="3dp" 
         android:textColor="@android:color/black" /> 

        <TextView 
         android:id="@+id/textView8" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignLeft="@+id/textView4" 
         android:layout_below="@+id/textView4" 
         android:layout_marginTop="3dp" 
         android:textColor="@android:color/black" /> 

        <TextView 
         android:id="@+id/textView9" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignLeft="@+id/textView5" 
         android:layout_below="@+id/textView5" 
         android:layout_marginTop="3dp" 
         android:textColor="@android:color/black" /> 
       </RelativeLayout> 
      </TableRow> 

      <TableRow 
       android:id="@+id/tableRow2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

       <RelativeLayout 
        android:id="@+id/relativeLayout3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1.0" > 

        <SeekBar 
         android:id="@+id/seekBar1" 
         android:layout_width="150dp" 
         android:layout_height="wrap_content" 
         android:layout_alignParentRight="true" 
         android:soundEffectsEnabled="true" /> 

        <TextView 
         android:id="@+id/textView10" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentLeft="true" 
         android:layout_centerVertical="true" 
         android:text="Volume 1" 
         android:textColor="@android:color/black" /> 
       </RelativeLayout> 
      </TableRow> 

      <TableRow 
       android:id="@+id/tableRow3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

       <RelativeLayout 
        android:id="@+id/relativeLayout4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1.0" > 

        <SeekBar 
         android:id="@+id/seekBar2" 
         android:layout_width="150dp" 
         android:layout_height="wrap_content" 
         android:layout_alignParentRight="true" 
         android:soundEffectsEnabled="true" /> 

        <TextView 
         android:id="@+id/textView11" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentLeft="true" 
         android:layout_centerVertical="true" 
         android:text="Volume 2" 
         android:textColor="@android:color/black" /> 
       </RelativeLayout> 
      </TableRow> 

      <TableRow 
       android:id="@+id/tableRow4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:baselineAligned="false" > 

       <LinearLayout 
        android:id="@+id/linearLayout1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1.0" 
        android:orientation="vertical" > 

        <Button 
         android:id="@+id/button1" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="right" 
         android:text="Save Volumes" /> 
       </LinearLayout> 
      </TableRow> 

      <TableRow 
       android:id="@+id/tableRow5" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" > 

       <FrameLayout 
        android:id="@+id/frameLayout3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1.0" 
        android:orientation="vertical" > 

        <TextView 
         android:id="@+id/textView12" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:layout_gravity="center_vertical|center_horizontal" 
         android:gravity="top|left" 
         android:scrollbars="vertical" 
         android:visibility="visible" /> 
       </FrameLayout> 
      </TableRow> 

      <TableRow 
       android:id="@+id/tableRow8" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

       <FrameLayout 
        android:id="@+id/frameLayout2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1.0" > 

        <ImageView 
         android:id="@+id/imageView1" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="right|center" /> 

        <TextView 
         android:id="@+id/textView13" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="right|center" 
         android:layout_marginRight="30dp" 
         android:clickable="true" 
         android:text="Detailed Instruction" /> 
       </FrameLayout> 
      </TableRow> 
     </TableLayout> 
    </ScrollView> 

</RelativeLayout> 

अग्रिम धन्यवाद!

+0

क्या आपकी समस्या हल हो गई है? कृपया मेरा उत्तर देखें क्योंकि यह आपकी आवश्यकता के अनुसार काम करता है। और अगर यह काम करता है तो इसे स्वीकार करें। –

उत्तर

2

समस्या ScrollView के अंदर स्क्रॉलव्यू है।

जब आप स्क्रॉलव्यू एंड्रॉइड के अंदर स्क्रॉलव्यू डालते हैं तो बस भ्रमित हो जाएं कि कौन सी स्क्रॉल व्यू छुआ है। तो कभी-कभी यह टच इवेंट देने में असमर्थ हो जाता है।

एक समय खोजने के बाद मुझे एक लिंक या ब्लॉग मिला जो इस समस्या को निकाल देगा और समाधान भी प्राप्त करेगा।

this ब्लॉग पर एक नज़र डालें। यह वही है जो आप खोज रहे हैं और मुझे यकीन है कि यह आपकी समस्या का समाधान करेगा।

अब समय का आनंद लें करने के लिए;)

+0

मैंने कोशिश की और अब मेरी समस्या हल हो गई है। इस उपयोगी उत्तर के लिए धन्यवाद। – Pari

0

सबसे पहले लेआउटपरैम को सेटिंग की आवश्यकता नहीं है क्योंकि आपने इसे एक्सएमएल लेआउट में दिया है।

और यदि आपके पास ऐसी लंबी स्ट्रिंग है तो इसे सीधे जावा कोड पर न रखें। इसके बजाय संसाधन स्ट्रिंग को उस स्ट्रिंग को डालें।

मानों पर जाएं, और strings.xml फ़ाइल खोलें और अपनी स्ट्रिंग को परिभाषित करें।

नीचे देखें:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string name="hello">Hello World, HelperStackOverflowActivity!</string> 
    <string name="app_name">HelperStackOverflow</string> 
    <string name="String1">"PUT YOUR STRING HERE" </string> 

</resources> 

कि जावा कोड में स्ट्रिंग सेट जब चाहें करने के बाद। के रूप में की तरह:

text = (TextView)findViewById(R.id.textView12); 
    text.setText(getResources().getString(R.string.String1)); 

यह सामान्य स्क्रॉल के रूप में अच्छा स्क्रॉल करें।

आशा है कि यह आपकी मदद करेगा।

आनंद लें। :)

+0

सबसे पहले प्रतिक्रिया देने के लिए खेद है और मैं यह सब कर रहा था जो आपने सुझाया लेकिन यह मदद नहीं कर सकता। TextView मेरे अपवाद के रूप में स्क्रॉल नहीं कर रहा है। मैं इस 'टेक्स्ट व्यू टेक्स्ट व्यू = (टेक्स्ट व्यू) findViewById (R.id.textView12) की तरह कर रहा हूं; \t \t टेक्स्ट व्यू टेक्स्ट = (टेक्स्ट व्यू) findViewById (R.id.textView12); text.setMovementMethod (ScrollingMovementMethod.getInstance()); textView.setText (getResources()। GetString (R.string.myString)); ' मैं यहां काम कर रहा हूं क्यों TextView स्क्रॉल नहीं कर रहा है? – Pari

+0

अपनी सभी लाइन हटाएं और बस इस लाइन को जोड़ें और कोशिश करें। टेक्स्ट देखें टेक्स्ट = (टेक्स्ट व्यू) findViewById (R.id.textView12); text.setText (। getResources() GetString (R.string.myString)); –

+0

यदि मैं यह कहता हूं कि टेक्स्टव्यू हाइट स्वचालित रूप से "रैप सामग्री" जैसे पाठ के अनुसार बढ़ता है और यदि मैं ऊंचाई को "1 9 3 पीएक्स" पर सेट करता हूं तो यह स्क्रॉल नहीं होता है। मुझे स्क्रॉलव्यू टेक्स्टव्यू का उपयोग किए बिना स्क्रॉल करने योग्य लगता है। – Pari

3

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

TextView text = (TextView) findViewById(R.id.textView12); 
text.setMaxLines(5); 
text.setMovementMethod(ScrollingMovementMethod.getInstance()); 

आप इसे और अधिक गतिशील बना सकते हैं। बस लाइनों की संख्या की गणना करके।

लाइनों की संख्या = (पिक्सेल में छवि ऊंचाई)/(पिक्सेल में पाठ फ़ॉन्ट आकार)

+1

मेरे टेक्स्टव्यू को बाहर निकाला। धन्यवाद। – jasonflaherty

3

मेरे मामले में मैं सिर्फ एक scrollview अंदर मेरे TextView डाल करने के लिए की जरूरत है। स्क्रॉलिंग बहुत चिकनी हो गई और उपयोगकर्ता हर बार खुशी से रहते थे!

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true" 
    > 
    <TextView 
     android:id="@+id/textview_about" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textIsSelectable="true" 
     android:textSize="20dp" /> 
</ScrollView> 
संबंधित मुद्दे