2012-06-20 49 views
5

मुझे एक संपादन टेक्स्ट की आवश्यकता है जो मेरी खिड़की की ऊंचाई में भरती है। मैं इस का उपयोग कर रहा:एंड्रॉइड - एडिटटेक्स्ट मल्टीलाइन ऊंचाई भरने के लिए मजबूर

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

<EditText 
    android:id="@+id/text_editor" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:background="#ff0000" 
    android:gravity="top|left" 
    android:inputType="textMultiLine" 
    android:textColor="@android:color/white" /> 

</ScrollView> 

लेकिन सभी मैं एक एक पंक्ति EditText कि लंबे समय तक किया जाएगा और स्क्रॉल करने योग्य एक बार मैं बहु वापसी बटन टाइपिंग पर कुछ लिखना है। मुझे पता है कि मैं लाइन नंबर सेट कर सकता हूं, लेकिन इस मामले में इसे विभिन्न उपकरणों पर काम करना चाहिए और प्रत्येक डिवाइस (मुझे लगता है) की अलग-अलग लाइनें हैं।

डिवाइस को ऊंचाई में भरने के लिए मैं इसे कैसे मजबूर कर सकता हूं?

कोई सुझाव?

उत्तर

2

कोशिश (scrollview के बिना) का उपयोग करें:

<EditText 
    android:id="@+id/text_editor" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:background="#ff0000" 
    android:gravity="top|left" 
    android:textColor="@android:color/white" /> 
+0

स्क्रॉलव्यू के बिना उपयोग करने में मदद मिली। –

0

आप कोड में जोड़ सकते हैं, तो इसे इस तरह होगा:

EditText et = new EditText(this); 
l.addView(et, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 100)); 

जहां 100 मतलब है कि यह चौड़ाई के 100dp करने जा रहा है। lLayout है आपके पास आपके मामले में (ScrollView) हो सकता है जो आप R.layout.name_of_the_scroll_view के साथ प्राप्त कर सकते हैं।

मुझे यकीन नहीं है लेकिन WRAP_CONTENT ऊंचाई की संपत्ति में डालने का प्रयास करें।

0
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <EditText 
     android:id="@+id/editText1" 
     android:scrollbars="vertical" <----------- 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:gravity="top|left" 
     android:ems="10" 
     android:text=" example text" /> 

</RelativeLayout> 

जावा इस सेट कोड में .....

ed1 = (EditText) findViewById(R.id.editText1); 
ed1.setMovementMethod(new ScrollingMovementMethod()); <-------- 

सभी डिवाइस में काम करेगा।

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

2

संपादन टेक्स्ट के लिए इसे सेट करने का प्रयास करें, मेरे पास एक ही चीज़ थी, यह काम करेगी।

<EditText 
android:id="@+id/text_editor" 
android:layout_width="match_parent" 
**android:layout_height="wrap_content"** 
android:background="#ff0000" 
android:gravity="top|left" 
android:inputType="textMultiLine" 
android:textColor="@android:color/white" /> 

और आप भी स्थापित करने के लिए आप वास्तव में कैसे कई लाइनों की जरूरत है इस एक का उपयोग कर सकते हैं,

android:lines="number of Lines" 
0

मेरे कोड यह मेरे लिए काम नहीं है।

<?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="#ffffff" 
android:orientation="vertical" > 

<ImageView 
    android:id="@+id/imageView20" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:contentDescription="@string/img_desc1" 
    android:src="@drawable/num74_head_payakorn" /> 

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

    <EditText 
     android:id="@+id/edtPayakorn" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:textSize="22sp" 
     android:clickable="false" 
     android:cursorVisible="false" 
     android:editable="false" 
     android:enabled="true" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:gravity="top|left" 
     android:scrollbars="vertical" 
     android:inputType="textMultiLine" /> 
    </TableRow> 
</LinearLayout>