Android Landscape mode cutting off my last EditText - android

I've got a problem in my application.
My layout contains:
ImageView
Button
Four EditText
When I change the emulator in landscape mode the ScrollView goes to the third EditText. The last EditText is not displayed in landscape mode.
My layout.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="60dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="235dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/formulario_foto"
android:background="#00A8EC"
android:src="#drawable/person"/>
<Button
android:layout_width="56dp"
android:layout_height="56dp"
android:id="#+id/formulario_foto_button"
android:layout_alignParentBottom='true'
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="20dp"
android:background="#drawable/formulario_foto_button"
android:elevation="5dp"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="20sp"/>
</RelativeLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:hint="Nome"
android:id="#+id/editTextNome" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:ems="10"
android:hint="E-mail"
android:id="#+id/editTextEmail" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:hint="Endereço"
android:id="#+id/editTextEndereco" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="phone"
android:ems="10"
android:hint="Telefone"
android:id="#+id/editTextTelefone" />
</LinearLayout>
</ScrollView>

It looks like ScrollView does not respect the margin of its child. This behavior has been noted in
Android ScrollView not respecting child's bottom margin
Scrollview doesn't scroll to the margin at the bottom
Scrollview extends beyond screen bottom
The workaround is to wrap your LinearLayout in a FrameLayout, ie.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="60dp"
android:orientation="vertical">
...
</LinearLayout>
</FrameLayout>
This is slightly inefficient, since it uses an extra ViewGroup. If you are able to do so, the more efficient solution would be to use paddingTop on your LinearLayout instead of the layout_marginTop, ie.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="60dp"
android:orientation="vertical">
...
</LinearLayout>

Change linear layout height to wrap_content

Related

Cannot see textview

I am trying to make a layout with this code :
<?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"
xmlns:card_view="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
>
<android.support.v7.widget.CardView
app:cardCornerRadius="#dimen/cardview_corner_radius"
app:cardElevation="2dp"
card_view:cardUseCompatPadding="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="#f27181"
android:id="#+id/charity_overview_card"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.sharesmile.share.views.LBTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#color/white"
android:padding="9dp"
android:text="Women Empowerment"
android:id="#+id/iv_charity_category_title"
/>
<ImageView
android:background="#color/colorPrimaryDark"
android:layout_width="128dp"
android:layout_height="126dp"
android:id="#+id/iv_charity_overview"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.sharesmile.share.views.LBTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_charity_amount"
android:textColor="#color/black"
android:textSize="15sp"
android:text="Test"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
but the last textview is not visible, even in the preview it is not showing, it shows like this :
As you can see the textview is not visible, i haven't given any weight, still facing this issue.
Also when i increase the size of the textview the value is visible as you can see here :
LinearLayout inside other parent LinearLayout with dynamic size will produce this type of issues. You should avoid nesting layout inside layout as much as possibile.
This issue can be simply fixed by removing the parent layout orientation.
For improvement
<CardView>
<LinearLayout> vertical
//Add 'N' child items here
</LinearLayout>
</CardView>
Change the following properties of your main LinearLayout, Make height and width to match_parent
android:layout_width="match_parent"
android:layout_height="match_parent"

How do I make my recyclerview taking all wrap_content, when its available, but shrink down, if not?

I am sitting a long time to get my layout working. There should be an EditText on top. A RecyclerView after that. An ImageButton after that. At the bottom of the activity should be a Button. This looks fine. There is a Space between the ImageButton and Button which has height=0dp and weight=1. Rest has height=wrap_content.
When I open up the keyboard, the RecyclerView keeps being full-sized. This doesnt look fine. I want it to make space to let the Buttons fit on the screen. It should be like that
I tried to make the RecyclerView height=0dp too, but then the Space doesnt work as it should. Their height would depend on each other weight. When I remove the Space and try to get the Button to the bottom while Recyclerview has height=0dp, it would fill the entire free space, so the ImageButton would stick to the Button instead of to the end of the list.
If I would put the ImageButton as the last element of the RecyclerView, it wouldnt be always on the screen when the List is too long.
Layout-XML-only solution would be appreciated.
#edit: My layout breaks completely when I add more items. This should be fixed with the same approach.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.edit.EditActivity">
<EditText
android:id="#+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:hint="#string/enter_name"
android:inputType="text|textAutoComplete|textAutoCorrect|textShortMessage"
android:maxLength="25" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:scrollbars="vertical"
app:layoutManager="android.support.v7.widget.LinearLayoutManager">
</android.support.v7.widget.RecyclerView>
<ImageButton
android:id="#+id/bt_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="8dp"
android:background="#null"
app:srcCompat="#drawable/twotone_add_circle_24" />
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/bt_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="save" />
</LinearLayout>
you can give weight to recyclerview
like this:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:hint="enter name"
android:inputType="text|textAutoComplete|textAutoCorrect|textShortMessage"
android:maxLength="25" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="8dp"
android:layout_weight="1"
android:scrollbars="vertical"
app:layoutManager="android.support.v7.widget.LinearLayoutManager">
</android.support.v7.widget.RecyclerView>
<ImageButton
android:id="#+id/bt_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="8dp"
android:background="#null"
app:srcCompat="#drawable/ic_delete" />
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/bt_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="save" />
</LinearLayout>

Background not filling entire screen in scrollview android

I'm developing an app and I need to fill the entire screen with a background, this view contains a scrollview. The problem is that the background is not covering the entire screen, it has a white stripe at the bottom, like the image below.
I have already tried many options of scaleType, like fitXY, centerInside, etc. none of them worked out.
My XML is below.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/signup_background" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="40dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/image_view_photo"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_gravity="center"
android:layout_marginBottom="25dp"
android:src="#drawable/camera_icon" />
<android.support.v7.widget.AppCompatEditText
android:id="#+id/edit_text_name"
style="#style/BaseEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/name_icon"
android:hint="#string/field_name"
android:inputType="textCapWords" />
<android.support.v7.widget.AppCompatEditText
android:id="#+id/edit_text_email"
style="#style/BaseEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/email_icon"
android:hint="#string/field_email"
android:inputType="textEmailAddress" />
<android.support.v7.widget.AppCompatEditText
android:id="#+id/edit_text_password"
style="#style/BaseEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/password_icon"
android:hint="#string/field_password"
android:inputType="textPassword" />
<android.support.v7.widget.AppCompatEditText
android:id="#+id/edit_text_confirm_password"
style="#style/BaseEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="35dp"
android:drawableLeft="#drawable/password_icon"
android:hint="#string/field_confirm_password"
android:inputType="textPassword" />
<com.jacksonueda.reachalert.Utils.LoadingButton
android:id="#+id/btn_signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="#string/action_sign_up" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
Can anyone help me? Thanks.
I think that you have to give background to ConstraintLayout with width wrap_content. also set your height for both ScrollView and ConstraintLayout wrap_content.
In constraint layout you have to specify constraint. You don't have specified constraint in ImageView
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/signup_background" />
Replace it with
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/signup_background"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintLeft_toLeftOf="parent"
card_view:layout_constraintRight_toRightOf="parent"
card_view:layout_constraintTop_toTopOf="parent" />
Try to use RelativeLayout instead of ConstraintLayout in your xml. Relative Layout is best for overlapping two elements of xml.
I got the answer, what I needed to do was to put a RelativeLayout as parent of the ScrollView, like below.
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/signup_background"
android:orientation="vertical"
android:padding="40dp">
...
</LinearLayout>
</ScrollView>
</RelativeLayout>

Add linearLayout below listView doesn't work

This is not working on my phone but I can see it in the Android Studio Design mode window. I need to place a LinearLayout or any view actually just below the listView. But I can't see it, only the listView fitting the whole height
<RelativeLayout 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:id="#+id/local_detalle_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="android.buendia.cl.pritz.fragments.locales.LocalDetalleFragment">
<view
android:id="#+id/banner"
class="com.android.volley.toolbox.NetworkImageView"
android:layout_width="match_parent"
android:layout_height="80dp"
android:scaleType="centerCrop"
app:srcCompat="?android:attr/textSelectHandleLeft" />
<TextView
android:id="#+id/current_category"
style="#style/current_category"
android:layout_below="#+id/banner"
android:text="TextView" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/current_category">
<ListView
android:id="#+id/list_view_local_detalle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:id="#+id/cart_bar"
style="#style/cart_bar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/cart_status"
style="#style/cart_bar_status"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:text="TextView" />
<Button
android:id="#+id/cart_next"
style="#style/cart_bar_next"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/cart_bar_next_button_text" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Set android:layout_below="#+id/list_view_local_detalle" for LinearLayout
Note : If you'r using weight for vertical linear layout then height must be 0 dp and if using for horizontal linear layout then width must be 0dp.

View below another view and vertically centered

Below is my layout. I want EditText to be on top of layout and I want VideoView to be vertically centered. EditText appears fine but I see my VideoView aligned below the EditText (not vertically centered). However if I remove android:layout_below="#+id/caption" then my VideoView is vertically centered but if the video is of larger height then it will come on top of EditText and I don't want that. How can I adjust VideoView such that it is both vertically centered and below EditText?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="5dp"
android:background="#FFFFFF"
>
<EditText
android:id="#+id/caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:maxLength="100"
android:hint="Hello"/>
<VideoView
android:id="#+id/previewvideo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_below="#+id/caption"
/>
</RelativeLayout>
Please check below code it's helpful for you
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:ems="10" >
<requestFocus />
</EditText>
<VideoView
android:id="#+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp" />
Use a LinearLayout as the root ViewGroup and specify the layout_gravity for the VideoView with a vertical orientation. This will place the items top to bottom as they are ordered in the layout.
<LinearLayout
android:orientation="vertical"
...
>
<EditText
.../>
<VideoView
...
android:layout_gravity="center_vertical"/>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="5dp"
android:background="#FFFFFF">
<EditText
android:id="#+id/caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:maxLength="100"
android:hint="Hello"/>
<VideoView
android:id="#+id/previewvideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_below="#+id/caption"/>
</RelativeLayout>
adding layout_below invalidates layout_centerVertical. Instead make the EditText use android:layout_above="#+id/previewvideo" and remove the layout_below on the VideoView.
You may have to tweak it a little more but that should get you started.

Categories

Resources