2 Views side by side with the same height - android

I'm using 2 inner Linearlayouts to divide my screen into 2 sections. It looks like this:
The first inner Layout has a TextView and a Button. The second one has a ImageView and also a Button. Now I want to get the same height for the TextView and ImageView without setting a fix value for layout_height. The left button should also be in line with the right button.
Here is my xml:
<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="horizontal"
tools:context="de.dk.masterfi.ActMain">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="280dp"
android:background="#drawable/border"
android:padding="10dp"
android:text="#string/welcome"/>
<Button android:id="#+id/button2" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Favoriten"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="280dp" android:src="#drawable/training"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Hauptmenü"/>
</LinearLayout>

try this, note the android:layout_weight="1" attribute for TextView and ImageView:
<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="horizontal"
tools:context="de.dk.masterfi.ActMain">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/border"
android:padding="10dp"
android:text="#string/welcome"/>
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Favoriten"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/training"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hauptmenü"/>
</LinearLayout>
</LinearLayout>

Try this:
android:layout_height = "0dp"
android:layout_weight = "1.0"
Change the weight according to your specs

Change your xml to
<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="horizontal"
tools:context="de.dk.masterfi.ActMain">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/border"
android:padding="10dp"
android:text="#string/welcome"/>
<Button android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Favoriten"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:src="#drawable/training"
android:layout_weight="1"/>
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hauptmenü"/>
</LinearLayout>
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_trail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
tools:context="com.nividbharat.educompanion.activities.TrailActivity">
<RelativeLayout
android:id="#+id/relLayout1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:layout_marginTop="16dp"
android:layout_weight="0.5"
android:background="#android:color/black"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button1"
android:background="#android:color/holo_red_dark" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relLayout2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="16dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:layout_weight="0.5"
android:background="#android:color/black">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button2"
android:background="#android:color/holo_red_dark" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button2" />
</RelativeLayout>
</LinearLayout>
This is how the preview of the layout look like,

Related

How do I design the CardView so its next to each other?

Hello! as the title suggest, I'm trying to put those two CardViews next to each other. Is it possible to do so. Currently this is what my xml looks like. Here's the code:
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/homeBackground"
android:orientation="vertical"
tools:context=".Home">
<LinearLayout
android:orientation="horizontal"
android:id="#+id/layout_user_information"
android:weightSum="4"
android:padding="8dp"
android:background="#color/colorButton"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/home_image"
app:srcCompat="#drawable/userboy"
android:layout_width="60dp"
android:layout_height="60dp" />
<LinearLayout
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id = "#+id/home_username"
android:text = "Username"
android:textColor="#android:color/white"
android:textSize="22sp"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TextView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:weightSum="4">
<androidx.cardview.widget.CardView
android:id="#+id/card_view_booking"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="8dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
app:srcCompat="#drawable/home_booking" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="#font/poppinsbold"
android:text="Booking" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:weightSum="4"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view_history"
android:layout_marginRight="8dp"
android:layout_width="0dp"
android:layout_weight="1"
app:cardCornerRadius="8dp"
android:layout_height="wrap_content"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
app:srcCompat="#drawable/home_history"
android:layout_width="50dp"
android:layout_gravity="center_horizontal"
android:layout_height="50dp" />
<TextView
android:text="History"
android:fontFamily="#font/poppinsbold"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
I have already match_parent for both layout width and height for the first LinearLayout. but no luck there. Is there any way I could solve this problem?
wrap the both layout that contains CardView with another linear Layout with
android:orientation="horizontal"
the whole code will look like
<?xml version="1.0" encoding="utf-8"?><?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:background="#color/homeBackground"
android:orientation="vertical"
tools:context=".Home">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:weightSum="4">
<androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view_booking"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_weight="1"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
app:srcCompat="#drawable/home_booking" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="#font/poppinsbold"
android:text="Booking" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:weightSum="4">
<androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view_history"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_weight="1"
app:cardCornerRadius="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
app:srcCompat="#drawable/home_history" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="#font/poppinsbold"
android:text="History" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Use a linear layout with orientation = "horizontal" and have the card view placed under it

How to set scroll view which expands due to background image on different devices?

In my app I have the main layout, having the linear layout as parent and child is scroll view and inside this scroll view, I have another linear layout.
Example would be
LinearLayout->
ScrollView->
LinearLayout-> (Setting Background Image here)
So if the background is very high resolution it will expand a lot, so I have resized the background so it could work on most devices as expansion is reduced but still in devices with different screen sizes has a lot of differences in sizes.
So the issue still persists, what is the proper way to handle this?
What screen looks like with background image with resolution (729*1296)
Background Image(729*1296)
After resizing background image with resolution (400*711) and running on the xxhdpi device it looks like this.
Background image(400*711)
So now I have a little scroll available. Which is good but applying on different devices can be tricky and there is a difference in layout sizes.
What I want on all devices is to look like this.
Background Image(What i want)
Without any resize of background image I want my layout to look like this in all devices, only 3 inner layouts (pics, audios, videos) should be visible rest should be scrolled.
This is the layout XML file.
<?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=".StartActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/pg5"
android:orientation="vertical"
android:weightSum="5"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<LinearLayout
android:id="#+id/gb_text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.55"
android:gravity="center|top"
android:orientation="vertical"
android:weightSum="3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.2"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center|top"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|top"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Duplicate Files Remover"
android:textColor="#android:color/white"
android:textSize="#dimen/DuplicateFileRemovertext" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"></LinearLayout>
</LinearLayout>
</LinearLayout>
<com.intrusoft.sectionedrecyclerviewapp.CircularProgressBar
android:id="#+id/circularProgress"
android:layout_width="#dimen/circularprogresswidth"
android:layout_height="#dimen/circularprogressheight"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/circularprogresstopmargin" />
<TextView
android:id="#+id/gb_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="TextView"
android:textColor="#android:color/white"
android:textSize="#dimen/totalavailablesize" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.45"
android:orientation="vertical"
android:weightSum="5">
<LinearLayout
android:id="#+id/scanimages_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:weightSum="2">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:id="#+id/piccardlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bluelayout"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"
android:paddingLeft="8dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/picicon"
android:scaleType="fitXY"
app:riv_corner_radius="12dip"
app:riv_mutate_background="true"
app:riv_oval="false"
app:riv_tile_mode="clamp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:paddingLeft="8dp"
android:text=" Pictures"
android:textColor="#android:color/white"
android:textSize="#dimen/Scanpicturestext" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="#+id/scanaudio_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:weightSum="2">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:id="#+id/audiocardlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/purplelayout"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"
android:paddingLeft="8dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/imageView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="1dp"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/playicon"
android:scaleType="fitXY"
app:riv_corner_radius="12dip"
app:riv_mutate_background="true"
app:riv_oval="false"
app:riv_tile_mode="clamp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:paddingLeft="8dp"
android:text=" Audios"
android:textColor="#android:color/white"
android:textSize="#dimen/Scanaudiostext" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="#+id/scanvideos_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:weightSum="2">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:id="#+id/videocardlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/redlayout"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"
android:paddingLeft="8dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/imageView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="1dp"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/vidicon"
android:scaleType="fitCenter"
app:riv_corner_radius="12dip"
app:riv_mutate_background="true"
app:riv_oval="false"
app:riv_tile_mode="clamp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:paddingLeft="8dp"
android:text="Videos"
android:textColor="#android:color/white"
android:textSize="#dimen/Scanvideostext" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="#+id/scandocs_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:weightSum="2">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:id="#+id/doccardlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/greenlayout"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"
android:paddingLeft="8dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/imageView5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="1dp"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/docxicon"
android:scaleType="fitXY"
app:riv_corner_radius="12dip"
app:riv_mutate_background="true"
app:riv_oval="false"
app:riv_tile_mode="clamp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:paddingLeft="8dp"
android:text="Docs"
android:textColor="#android:color/white"
android:textSize="#dimen/Scandocumentstext" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
I just had a look at layout code. It is showing this kind of behavior because you are assigning your background to a Linear Layout which has a height of wrap_content. So the size of linear layout changes with the background provided. You should put the background in an imageview.
However, in my opinion you should change the overall hierarchy of your layout. It should be something like this:
RelativeLayout
ImageView
ScrollView
LinearLayout-> this will contain your code, which you want to scroll
A simple structure xml would be like this,
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:src="#drawable/background"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Your Layout code goes here -->
</LinearLayout>
</ScrollView>
</RelativeLayout>

Clarifying layout

This is my layout:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/under_line_edit">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/ic_assignment" />
<EditText
android:id="#+id/editName"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/under_line_edit"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="30dp"
android:background="#drawable/under_line_edit">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/img"
android:background="#drawable/ic_person_outline" />
<EditText
android:id="#+id/editUsername"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/under_line_edit"/>
</LinearLayout>
</ScrollView>
I don't understand why if I put match_parent on the imageView and editTex, the latter do not occupy the entire screen in height.
Instead I get two rows as I wanted but I do not understand why
Why?
Please try this:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:background="#drawable/under_line_edit">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/ic_assignment" />
<EditText
android:id="#+id/editName"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/under_line_edit"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="30dp"
android:background="#drawable/under_line_edit">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/img"
android:background="#drawable/ic_person_outline" />
<EditText
android:id="#+id/editUsername"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/under_line_edit"/>
</LinearLayout>
</ScrollView>

My scrollView does not scroll?

I have a main layout that fits the screen, then i want it to scroll down to show the button,
i tried removing fillviewport but it then collapses the view,
I even made the linear layout wrap_content and it does the same, collapses the view
<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"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:orientation="vertical">
<ScrollView
android:id="#+id/inner_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/detail_note_date_text"
android:fillViewport="true"
android:>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/detail_title_edit_text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:backgroundTint="#android:color/background_light"
android:hint="#string/title_hint"
android:inputType="textShortMessage"
android:textSize="24dp"
/>
<EditText
android:id="#+id/detail_note_edit_text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="48"
android:gravity="top"
android:hint="#string/note_hint"
android:textSize="16dp"
/>
<RadioGroup
android:id="#+id/reminder_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/radio_no_set_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_button_no_set_reminder"/>
<RadioButton
android:id="#+id/radio_set_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_button_set_reminder"/>
</RadioGroup>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
<TextView
android:id="#+id/detail_note_date_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_weight="2"
tools:text="#string/demo_date"/>
Try as below:
<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"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<ScrollView
android:id="#+id/inner_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/detail_note_date_text"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/detail_title_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#android:color/background_light"
android:hint="#string/title_hint"
android:inputType="textShortMessage"
android:textSize="24dp"
/>
<EditText
android:id="#+id/detail_note_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:hint="#string/note_hint"
android:textSize="16dp"
/>
<RadioGroup
android:id="#+id/reminder_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/radio_no_set_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_button_no_set_reminder"/>
<RadioButton
android:id="#+id/radio_set_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/radio_button_set_reminder"/>
</RadioGroup>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
<TextView
android:id="#+id/detail_note_date_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/demo_date"/>
</RelativeLayout>

Android soft keyboard covers Edittext android

Android: show soft keyboard automatically covers half of Edittext field after clicking on that particular Edittext implemented in the bottom of the layout. When request focus on EditText soft keyboard opens and it will shift the layout upward but covers up the half of Edittext field.
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.12"
android:background="#color/green"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/ll_back"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="#drawable/btn_selector"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_nav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_back"
android:focusableInTouchMode="true" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_circle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/btn_selector"
android:gravity="center_vertical|start"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circleView"
android:layout_width="#dimen/list_circle"
android:layout_height="#dimen/list_circle"
android:layout_gravity="center"
android:layout_margin="7dp"
android:src="#drawable/logo8" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_id"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="#drawable/btn_selector"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="\#gaurav.yadav"
android:textColor="#android:color/white"/>
<TextView
android:id="#+id/textView81"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1d" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"></LinearLayout>
<LinearLayout
android:id="#+id/ll_p"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.2"
android:gravity="center_vertical|right"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_post"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/btn_selector"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.87"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerView_topcollege"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.12"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/ll_attachment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/ic_menu_gallery" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="2"
android:background="#drawable/bg_edittext"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="#00000000"
android:hint="Write a Answer...."
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#android:drawable/ic_menu_send"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView27"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
set flag in the manifest as,
android:windowSoftInputMode="stateHidden|adjustPan"
Put your required code in scrollview, than for activity class you have to set one property
android:windowSoftInputMode="adjustResize"
set focus to dummy layout or any view in your xml
like
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:orientation="vertical" >

Categories

Resources