Reputation: 105
I have found similar questions about this problem and as I am a beginner, I am unable to figure out why none of the solutions is working for me. I have a TabLayout and each tab holds a fragment. In one fragment, I have an EditText at the middle of the layout and whenever I try to write in the EditText, the keyboard hides half of the EditText. Many suggested adding android:windowSoftInputMode="adjustPan|adjustResize"
in the manifest file but it did not work as the EditText is within a fragment, not an activity (I guess). I yet added it to the manifest file in the mother activity of the tab fragments, did not work. Can anyone suggest me how to handle this? Here is my fragment layout code:
<FrameLayout 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"
android:background="@drawable/background"
android:paddingTop="15dp"
tools:context="com.example.lenovo.memcreator.fragments.CreateMemoryFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical"
tools:ignore="UselessParent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="@string/create_a_new_memory"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:weightSum="8"
tools:ignore="DisableBaselineAlignment">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="@string/memory_name"
android:textSize="17sp" />
<EditText
android:id="@+id/memory_name"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_weight="5"
android:background="@drawable/edit_text_border"
android:gravity="top"
android:inputType="textMultiLine"
android:padding="5dp"
android:scrollbars="vertical"
android:textColor="#c2000000"
android:textCursorDrawable="@null"
android:textSize="16sp"
tools:ignore="RtlHardcoded" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="8"
tools:ignore="DisableBaselineAlignment">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_weight="3"
android:orientation="vertical"
android:weightSum="10">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6"
android:contentDescription=""
android:scaleType="centerCrop"
android:src="@drawable/no_image"
tools:ignore="ContentDescription,NestedWeights" />
<Button
android:id="@+id/btn_add_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:text="@string/browse"
android:textAllCaps="false" />
<Button
android:id="@+id/btn_capture_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:text="@string/capture"
android:textAllCaps="false" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="220dp"
android:layout_marginLeft="15dp"
android:layout_weight="5"
android:orientation="vertical"
tools:ignore="RtlHardcoded">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="@string/post_mem"
android:textSize="17sp" />
<EditText
android:id="@+id/memory_text"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@drawable/edit_text_border"
android:gravity="top"
android:inputType="textMultiLine"
android:minLines="6"
android:padding="5dp"
android:scrollbars="vertical"
android:textColor="#c2000000"
android:textCursorDrawable="@null"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/btn_create_memory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/colorPrimary"
android:text="@string/create_memory"
android:textAllCaps="false"
android:textColor="#ffffff" />
</LinearLayout>
</FrameLayout>
Here, how it looks before typing: http://imgur.com/a/IXT7V And while typing: https://i.sstatic.net/mRvGa.jpg
Any kind of help is appreciated.
Upvotes: 0
Views: 482
Reputation: 119
Only put this in Manifest
file's 'Activity'
android:windowSoftInputMode="adjustPan"
Upvotes: 0
Reputation: 5550
Use this same code with ScrollView
:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:background="@drawable/background"
android:paddingTop="15dp"
tools:context="com.example.lenovo.memcreator.fragments.CreateMemoryFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical"
tools:ignore="UselessParent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="@string/create_a_new_memory"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:weightSum="8"
tools:ignore="DisableBaselineAlignment">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="@string/memory_name"
android:textSize="17sp" />
<EditText
android:id="@+id/memory_name"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_weight="5"
android:background="@drawable/edit_text_border"
android:gravity="top"
android:inputType="textMultiLine"
android:padding="5dp"
android:scrollbars="vertical"
android:textColor="#c2000000"
android:textCursorDrawable="@null"
android:textSize="16sp"
tools:ignore="RtlHardcoded" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="8"
tools:ignore="DisableBaselineAlignment">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_weight="3"
android:orientation="vertical"
android:weightSum="10">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6"
android:contentDescription=""
android:scaleType="centerCrop"
android:src="@drawable/no_image"
tools:ignore="ContentDescription,NestedWeights" />
<Button
android:id="@+id/btn_add_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:text="@string/browse"
android:textAllCaps="false" />
<Button
android:id="@+id/btn_capture_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:text="@string/capture"
android:textAllCaps="false" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="220dp"
android:layout_marginLeft="15dp"
android:layout_weight="5"
android:orientation="vertical"
tools:ignore="RtlHardcoded">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="@string/post_mem"
android:textSize="17sp" />
<EditText
android:id="@+id/memory_text"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@drawable/edit_text_border"
android:gravity="top"
android:inputType="textMultiLine"
android:minLines="6"
android:padding="5dp"
android:scrollbars="vertical"
android:textColor="#c2000000"
android:textCursorDrawable="@null"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/btn_create_memory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/colorPrimary"
android:text="@string/create_memory"
android:textAllCaps="false"
android:textColor="#ffffff" />
</LinearLayout>
</ScrollView>
Upvotes: 0