在Android版的EditText滚动启用 [英] Android enabling scrolling on edittext
问题描述
这里只是一个简单的问题。我有一个滚动视图内的EditText。这是关于我的EditText code
just a simple question here. I have a edittext inside a scrollview. Here is my code regarding edittext
<ScrollView 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"
>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="899dp" >
<LinearLayout
android:id="@+id/LL1"
android:layout_width="match_parent"
android:layout_height="320dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/ivMainPic"
android:layout_width="match_parent"
android:layout_height="320dp"
/>
</LinearLayout>
<TextView
android:id="@+id/tvDescription"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_below="@+id/LL1"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="@string/strDescription"
android:textSize="14dp"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"/>
<TextView
android:id="@+id/tvCondition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tvDescription"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dip"
android:text="@string/strCondition"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/btnGetOffer"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="40dip"
android:layout_below="@+id/etConditionBody"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:text="@string/strGetOffer"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:background="@drawable/roundedcorner"
android:textStyle="bold" />
<TextView
android:id="@+id/etConditionBody"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="@+id/tvCondition"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:gravity="top"
android:paddingBottom="20dip"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:paddingTop="20dip"
android:scrollbars="vertical"
android:background="@drawable/edittextborder"/>
</RelativeLayout>
</ScrollView>
现在我在做什么是使它滚动和不可编辑的EditText,因为我对我的分贝feching其文本。
我试图用这个code
Now what I am doing is making it scrollable and a not editable edittext because I am feching its text on my db. I tried using this code
etConditionBody= (EditText) findViewById(R.id.etConditionBody);
etConditionBody.setScroller(new Scroller(getBaseContext()));
etConditionBody.setMaxLines(8);
etConditionBody.setVerticalScrollBarEnabled(true);
etConditionBody.setMovementMethod(new ScrollingMovementMethod());
etConditionBody.setText("wew \n wew2 \n wew3 \n wew4 \n wew \n wew2 \n wew3 \n wew4 \n wew \n wew2 \n wew3 \n wew4 \n wew3 \n wew4 \n wew \n wew2 \n wew3 \n taena");
,但它不滚动,它只是限制我行8
but it is not scrolling, it just limit my lines to 8
我用code基于此链接
<一href=\"http://stackoverflow.com/questions/8417454/how-to-enable-vertical-scrollbar-of-an-edittext-programmatically\">how使垂直滚动条的一个EditText 的编程
http://stackoverflow.com/questions/5831392/how-to-make-edittext-in-android-scrollable
但它不是工作
i used that code based on this links how to enable vertical scrollbar of an edittext programmatically http://stackoverflow.com/questions/5831392/how-to-make-edittext-in-android-scrollable but it isnt working
推荐答案
使用,而不是为这一个EditText一个TextView。您可以使用,滚动滚动型如
Use a TextView instead of an edittext for this. You can use a scrollview for for the scrolling Such as
<ScrollView
android:layout_width="match_parent"
android:layout_height="300dp">
<TextView
android:id="@+id/tvConditionBody"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</ScrollView>
这篇关于在Android版的EditText滚动启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!