[英]How to turn EditText to editable text-file like NotePad
Hi 你好
My problem is, that when I have a blank screen with ScrollView
and EditText
. 我的问题是,当我在ScrollView
和EditText
出现空白屏幕时。 I wanted my app to allow user to write what ever and where ever he/she wants, BUT when I ran the app, you were only allowed to type in the middle. 我希望我的应用程序允许用户写他/她想要的任何东西, 但是当我运行该应用程序时,只允许您在中间输入内容。 (I stretched the EditText to cover the whole screen) (我拉伸了EditText以覆盖整个屏幕)
Here is my screen: 这是我的屏幕:
Here is the screen I should/need to have: 这是我应该/需要的屏幕:
Here is the code: 这是代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="onhar.personalnote.Writing_Table">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="1000dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="1000dp">
</RelativeLayout>
</ScrollView>
</RelativeLayout>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/plusicon" />
<include layout="@layout/content_writing__table" />
</android.support.design.widget.CoordinatorLayout>
Is this possible? 这可能吗?
In your XML you need android:gravity="top|start"
on your EditText. 在您的XML中,您需要在EditText上使用android:gravity="top|start"
。
If you want to do it in Java code then it's: myEditText.setGravity(Gravity.TOP | Gravity.START);
如果要用Java代码myEditText.setGravity(Gravity.TOP | Gravity.START);
: myEditText.setGravity(Gravity.TOP | Gravity.START);
Where position is an int: 如果position是一个int:
editText1.setSelection(position);
editText1.setSelection(0); //You can set it as 0.
EditText yourEt= (EditText) findViewById(R.id.yourEt);
yourEt.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEt, InputMethodManager.SHOW_IMPLICIT);
// You can set focus of edittext only.
// Please share your code.
First thing is that you should never use fixed height. 第一件事是永远不要使用固定高度。 And answer to your query is add this attribute android:fillViewport="true"
to your ScrollView
. 对您的查询的答案是将此属性android:fillViewport="true"
到ScrollView
。 Also add android:gravity="top"
to you EditText. 还要将android:gravity="top"
到您的EditText中。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/edt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:hint="Hello" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.