Reputation: 23
Hi
My problem is, that when I have a blank screen with ScrollView
and 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)
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?
Upvotes: 0
Views: 158
Reputation: 1954
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
. Also add android:gravity="top"
to you 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>
Upvotes: 0
Reputation: 683
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.
Upvotes: 0
Reputation: 4686
In your XML you need android:gravity="top|start"
on your EditText.
If you want to do it in Java code then it's: myEditText.setGravity(Gravity.TOP | Gravity.START);
Upvotes: 1
Reputation: 4130
Where position is an int:
editText1.setSelection(position);
editText1.setSelection(0); //You can set it as 0.
Upvotes: 0