How to modify layout to display input field when keyboard is shown? - android

I use the following layout
<?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="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp"
android:isScrollContainer="true">
<TextView
android:id="#+id/wizard4_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:scrollbars="vertical"
android:text="#string/wizard4_title"
android:textColor="#0088cc"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="0dp"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:id="#+id/wizard4_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="fill_horizontal"
android:scrollbars="vertical"
android:text="#string/wizard4_text1"
android:textSize="18sp" />
<EditText
android:id="#+id/wizard4_name"
android:hint="#string/wizard4_name_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/wizard4_text3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="fill_horizontal"
android:scrollbars="vertical"
android:text="#string/wizard4_text3"
android:textSize="18sp" />
<EditText
android:id="#+id/wizard4_address"
android:hint="#string/wizard4_address_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<Button
android:id="#+id/wizard4_btn_back"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/wizard_back" />
<Button
android:id="#+id/wizard4_btn_next"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/wizard_next" />
</LinearLayout>
</LinearLayout>
It is displayed as part of ViewAnimator:
viewAnimator = new ViewAnimator(this);
...
View step4 = View.inflate(getBaseContext(), R.layout.wizard4, null);
viewAnimator.addView(step4);
setContentView(viewAnimator);
When user clicks on the second input field (wizard4_address), soft keyboard is display, which hides the input field. Currently buttons wizard4_btn_next and wizard4_btn_back are also displayed when keyboard is shown, I don't need it. But I should keep them always at the bottom.

Try this. Hope you will get what you want.
<?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="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/wizard4_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:scrollbars="vertical"
android:text="#string/wizard4_title"
android:textColor="#0088cc"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/wizard4_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="fill_horizontal"
android:scrollbars="vertical"
android:text="#string/wizard4_text1"
android:textSize="18sp" />
<EditText
android:id="#+id/wizard4_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/wizard4_name_hint" />
<TextView
android:id="#+id/wizard4_text3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="fill_horizontal"
android:scrollbars="vertical"
android:text="#string/wizard4_text3"
android:textSize="18sp" />
<EditText
android:id="#+id/wizard4_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/wizard4_address_hint" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp" >
<Button
android:id="#+id/wizard4_btn_back"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/wizard_back" />
<Button
android:id="#+id/wizard4_btn_next"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/wizard_next" />
</LinearLayout>

Related

Android - height of multiline button with layout_weight set

I have the following layout for my dialog:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<TextView
style="#style/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="#string/practice_question" />
<TextView
android:id="#+id/dialog_select_question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:textColor="#color/primary_text"
android:textSize="16sp"
tools:ignore="RtlHardcoded" />
<ListView
android:id="#+id/dialog_select_answers"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/dialog_select_board_button"
style="?attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="#string/practice_look_board" />
<Button
android:id="#+id/dialog_select_answer_button"
style="?attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="#string/practice_answer" />
</LinearLayout>
</LinearLayout>
There is a problem with bottom buttons:
I want the first button not to be cropped. I've set android:layout_height="wrap_content" but that doesn't helped.
P.S. If I change button text from "Look on the board" to "Look on the\nboard" all works fine. But I want to make the second button optional, so the first button may match the whole parent's width.
I have changed some of your code please try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/dialog_select_title"
style="#style/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="#string/practice_question" />
<TextView
android:id="#+id/dialog_select_question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/dialog_select_title"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:textColor="#color/primary_text"
android:textSize="16sp"
tools:ignore="RtlHardcoded" />
<ListView
android:id="#+id/dialog_select_answers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/dialog_select_question" />
<LinearLayout
android:id="#+id/dialog_select_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/dialog_select_answers"
android:orientation="horizontal">
<Button
android:id="#+id/dialog_select_board_button"
style="?attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="#string/practice_look_board" />
<Button
android:id="#+id/dialog_select_answer_button"
style="?attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="#string/practice_answer" />
</LinearLayout>
</RelativeLayout>

Scroll is not getting enabled

I have designed a signup screen in which I have a Scroll view , But Scroll view is not working.
I am not able to find why Scroll is not working , Help me with this.
Below is the code for reference:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<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"
>
<ImageView
android:id="#+id/sign_up_profile_image"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:background="#drawable/shape_rectangle_rounded_corner"
android:padding="10dp"
android:scaleType="fitXY"
android:src="#drawable/icon_avatar" />
<RelativeLayout
android:id="#+id/container_two"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/container_three"
android:layout_below="#+id/sign_up_profile_image"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="20dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/first_last_name_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<ui.customviews.MaterialEditText
android:id="#+id/sign_up_first_name_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="1dp"
android:layout_marginTop="2dp"
android:layout_weight="50"
android:hint="#string/first_name_hint"
android:imeOptions="actionNext"
android:inputType="textPersonName"
android:textSize="18sp"
app:baseColor="#363636"
app:floatingLabel="normal"
app:primaryColor="#000000" />
<customviews.MaterialEditText
android:id="#+id/sign_up_last_name_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:layout_marginTop="2dp"
android:layout_weight="50"
android:hint="#string/last_name_hint"
android:imeOptions="actionNext"
android:inputType="textPersonName"
android:textSize="18sp"
app:baseColor="#363636"
app:floatingLabel="normal"
app:primaryColor="#000000" />
</LinearLayout>
<ui.customviews.MaterialEditText
android:id="#+id/sign_up_email_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/first_last_name_container"
android:hint="#string/email"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:textSize="18sp"
app:baseColor="#363636"
app:floatingLabel="normal"
app:primaryColor="#000000"
/>
<ui.customviews.MaterialEditText
android:id="#+id/sign_up_password_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/sign_up_email_edit_text"
android:hint="#string/password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:textSize="18sp"
app:baseColor="#363636"
app:floatingLabel="normal"
app:primaryColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/container_three"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="#dimen/activity_vertical_margin">
<TextView
android:id="#+id/sign_up_terms_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:gravity="center_horizontal"
android:lineSpacingExtra="2dp"
android:lineSpacingMultiplier="1.2"
android:text="By signing up, you accept to the Terms and Conditions and Privacy Policy"
android:textColor="#6b6b6b"
android:textSize="14sp" />
<Button
android:id="#+id/sign_up_accept_button"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/sign_up_terms_text_view"
android:layout_marginLeft="#dimen/activity_vertical_margin"
android:layout_marginRight="#dimen/activity_vertical_margin"
android:background="#025961"
android:text="#string/accept_and_signup"
android:textColor="#android:color/white"
android:textSize="14sp" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
Try Like this, Add inside Linear layout , it will Scroll till End of the Page.
<RelativeLayout 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">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
// Your xml Code Put Here
</LinearLayout>
</ScrollView>
</Relativelayout>
solution can be change ScrollView to:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
>
Then you should change nested's layout height as well

How i prevent automatic focus on create activity of scroll view

When activity is create the focus is automatic transfer on scroll view edit text box but i want to stop this process, i want when user touch on edit text box then focus transferred on scroll view.Pleas help me.
<?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:orientation="vertical"
android:background="#drawable/new_background"
android:descendantFocusability="afterDescendants">
<LinearLayout
android:id="#+id/ll_Login_ContentHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/new_background"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="#dimen/padding_top_bottom"
android:paddingLeft="#dimen/padding_left"
android:paddingRight="#dimen/padding_right"
android:paddingTop="#dimen/padding_top_bottom"
android:weightSum="1" >
<LinearLayout
android:id="#+id/ll_Login_Content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="1" >
<ImageView
android:id="#+id/imgview_login_cabmapsLogo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight=".7"
android:scaleType="centerInside"
android:src="#drawable/new_cabmaps_logo" />
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="200dip" >
<LinearLayout
android:id="#+id/ll_Login_Content1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".3"
android:layout_marginTop="#dimen/Login_VerticalMargin"
android:orientation="vertical" >
<EditText
android:id="#+id/Edtxt_Login_UserNm"
android:layout_width="match_parent"
android:layout_height="#dimen/Edtxt_height"
android:background="#color/new_EdtxtBg"
android:drawableLeft="#drawable/new_email"
android:drawablePadding="#dimen/drawable_padding"
android:cursorVisible="true"
android:gravity="left|center_vertical"
android:hint="#string/UserNm"
android:imeOptions="actionNext"
android:inputType="textPersonName|textNoSuggestions"
android:paddingLeft="#dimen/view_padding_left"
android:textSize="#dimen/textsize" />
<EditText
android:id="#+id/Edtxt_Login_Password"
android:layout_width="match_parent"
android:layout_height="#dimen/Edtxt_height"
android:layout_marginTop="#dimen/Login_VerticalMargin"
android:background="#color/new_EdtxtBg"
android:drawableLeft="#drawable/new_password"
android:drawablePadding="#dimen/drawable_padding"
android:gravity="left|center_vertical"
android:hint="#string/Password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:paddingLeft="#dimen/view_padding_left"
android:textSize="#dimen/textsize" />
<LinearLayout
android:id="#+id/ll_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/Login_VerticalMargin"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1" >
<Button
android:id="#+id/btn_Login_NewUser"
android:layout_width="match_parent"
android:layout_height="#dimen/btn_height"
android:layout_weight=".50"
android:background="#color/new_OrangeBtnColor"
android:text="SIGN UP"
android:textColor="#color/TextColor"
android:textSize="#dimen/btntextsize" />
<Button
android:id="#+id/btn_Login_login"
android:layout_width="match_parent"
android:layout_height="#dimen/btn_height"
android:layout_marginRight="5dp"
android:layout_weight=".50"
android:layout_marginLeft="5dp"
android:background="#color/new_OrangeBtnColor"
android:text="LOGIN"
android:textColor="#color/TextColor"
android:textSize="#dimen/btntextsize" />
</LinearLayout>
<TextView
android:id="#+id/tv_OR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/new_or"
android:layout_marginTop="#dimen/Login_VerticalMargin"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/ll_Login_Content2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/Login_VerticalMargin"
android:orientation="horizontal"
>
<Button
android:id="#+id/loginViaFB"
android:layout_width="match_parent"
android:layout_height="#dimen/btn_height"
android:background="#drawable/new_fb"
android:onClick="onSocialMediaLoginClick"
android:tag="1"
android:layout_weight=".50"
/>
<Button
android:id="#+id/loginViaTwitter"
android:layout_width="match_parent"
android:layout_height="#dimen/btn_height"
android:layout_marginLeft="10dp"
android:background="#drawable/new_twitter"
android:onClick="onSocialMediaLoginClick"
android:tag="2"
android:layout_weight=".50"
/>
</LinearLayout>
<Button
android:id="#+id/btnForgotPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#android:color/transparent"
android:text="#string/ForgotPassword"
android:layout_gravity="center_horizontal"
android:textColor="#android:color/background_light"
android:autoLink="all" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_Login_Content1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".3"
android:layout_marginTop="#dimen/Login_VerticalMargin"
android:orientation="vertical" >
You can add this line in above layout android:focusableInTouchMode="true"

Add multiple ListView lists in one single layout in Android

I am trying to add 3 or more lists in a layout xml. I didn't expect this to be a problem, but I don't see all the lists(and they get populated) and the view does not scroll. I need an opinion to what stupid stuff I am doing here, please.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/googleDrawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" >
<RelativeLayout
android:id="#+id/navigationHeader"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/wallpaper"
android:paddingTop="16dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/activity_horizontal_margin"
android:orientation="vertical" >
<EditText
android:id="#+id/searchTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search" />
<TextView
android:id="#+id/txtUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_green_light"
android:text="Hello, user"
android:textColor="#android:color/white"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_light"
android:text="description"
android:textColor="#android:color/white" />
</LinearLayout>
</RelativeLayout>
<ScrollView
android:id="#+id/scrollojt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/navigationHeader"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/activity_horizontal_margin" >
<View
android:id="#+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:background="#1f000000" />
<TextView
android:id="#+id/questionsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/separator"
android:text="#string/questions_label"
android:textAllCaps="true"
android:textColor="#android:color/black" />
<ListView
android:id="#+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/questionsTitle"
android:background="#android:color/holo_green_dark"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollbars="vertical" />
<TextView
android:id="#+id/appsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/drawerList"
android:text="#string/apps_label"
android:textAllCaps="true"
android:textColor="#android:color/black" />
<ListView
android:id="#+id/drawerList2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/appsTitle"
android:background="#android:color/holo_red_dark"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollbars="vertical" />
<TextView
android:id="#+id/groupsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/drawerList2"
android:text="#string/groupapps_label"
android:textAllCaps="true"
android:textColor="#android:color/black" />
<ListView
android:id="#+id/drawerList3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/groupsTitle"
android:background="#android:color/holo_blue_bright"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollbars="vertical" />
<TextView
android:id="#+id/dmTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/drawerList3"
android:text="#string/directapps_label"
android:textAllCaps="true"
android:textColor="#android:color/black" />
<ListView
android:id="#+id/drawerList4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dmTitle"
android:background="#android:color/holo_green_light"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollbars="vertical" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Use just one ListView with an ArrayAdapter.
how to use arrayadapter
If you need help customizing the array adapter, just search on google or ask me ;)

Android - EditText isn't filling up available space in a fragment?

I'm having an issue with my EditText (with id of body) not filling up the available space in my layout. I've been searching everywhere and experimenting with numerous resources, but I just simply can not seem to get it and have been spending hours on literally just this.. I'm guessing there is an issue with how my entire layout is set up, and probably can't just make a tweak in EditText. By the way this layout is being used in a fragment, maybe that changes things? I'm not sure, what do you guys think? Thanks for any and all help! Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title" />
<EditText android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/body" />
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="write those saucy lyrics"
android:layout_marginTop="5dp"
android:scrollbars="vertical" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnEmail"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/btnEmail"
android:alpha="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I'm looking for my design to look like this (taken from my graphical layout editor):
However on my device it looks like this(snapshot from my device):
Try this..
Change android:layout_height="wrap_content" to android:layout_height="0dp"
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical" />
// try this way,hope this will help you...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/title"/>
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="#string/body"
android:layout_marginTop="5dp"
android:scrollbars="vertical" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btnEmail"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/btnEmail"
android:alpha="1" />
</LinearLayout>
</LinearLayout>
Make
android:layout_height="match_parent"
instead of
android:layout_height="wrap_content"
in Body edit text
So that it becomes
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:scrollbars="vertical" />
UPDATE:
Plz try following layout
<!-- Put the buttons at the bottom -->
<RelativeLayout
android:id="#+id/rel_lay_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Confirm" />
<Button
android:id="#+id/btnEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:alpha="1"
android:text="Emial" />
</RelativeLayout>
<!-- Put the title layout at the top of parent -->
<LinearLayout
android:id="#+id/lin_lay_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<EditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<!-- Occupy rest of the space of screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_above="#id/rel_lay_btn"
android:layout_below="#id/lin_lay_title">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Body" />
<EditText
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="top"
android:layout_weight="1"
android:scrollbars="vertical" />
</LinearLayout>

Categories

Resources