How can I make this form on Android? - java

I have tried to make this small form in Android, but have not been able to make the space in the third and fourth rows.

While you can implement this using a RelativeLayout, it is an ideal candidate for using ConstraintLayout which will let you specify element locations relative to each other and how they should expand/reposition themselves as the window resizes on tablets or in multiwindow mode.

Something like this :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apellidos"/>
<EditText
android:id="#+id/editText"
android:layout_toRightOf="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hind="Apellidos"/>
<LinearLayout
android:layout_below="#+id/editText"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_weight="1"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Ciudad"/>
<EditText
android:layout_toRightOf="#+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hind="Apellidos"/>
</RelativeLayout>
<RelativeLayout
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Ciudad"/>
<EditText
android:layout_toRightOf="#+id/text3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hind="Apellidos"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
Edit :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/name"
android:orientation="vertical"
android:gravity="right"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:id="#+id/text"
android:padding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apellidos"/>
<TextView
android:id="#+id/text1"
android:padding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apelli"/>
</LinearLayout>
<LinearLayout
android:id="#+id/value"
android:orientation="vertical"
android:layout_toRightOf="#+id/name"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/text"
android:hind="Apellidos" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_weight="2"
android:layout_toRightOf="#+id/text2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:hind="Apellidos"/>
<TextView
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:id="#+id/text2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Ciudad"/>
<EditText
android:layout_weight="2"
android:layout_toRightOf="#+id/text2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hind="xyz"/>
</LinearLayout>
</LinearLayout>

Related

Align text in RecyclerView with titles

Hello I have made a RecyclerView with orders. But the list in the popup isnt't aligned with the titles. Because pictures say more than words, here you can see it:
But what I need is something like that:
How could I make this work? How can I nicely define the columns so that each article fits nicely under the heading?
Here is my RecyclerView:
<?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="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:id="#+id/order_overview_artikel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Artikel"
android:layout_marginRight="10dp"
android:textSize="16dp"/>
<TextView
android:id="#+id/order_overview_anzahl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anzahl"
android:layout_marginRight="10dp"
android:textSize="16dp"/>
<TextView
android:id="#+id/order_overview_preis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preis"
android:textSize="16dp"/>
</LinearLayout>
And this is the pop up:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="15dp">
<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:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Bestellübersicht"
android:textAlignment="center"
android:textSize="25dp"
android:textStyle="bold"></TextView>
<TextView
android:id="#+id/order_overview_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="0"
android:textAlignment="center"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:text="Produkt"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="Anzahl"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="Preis"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
</LinearLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview_order_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.airbnb.lottie.LottieAnimationView
android:layout_width="match_parent"
android:layout_height="128dp"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="#raw/walkingburger" />
<Button
android:id="#+id/btn_order_overview_finish"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:background="#drawable/button_order_checkout"
android:backgroundTint="#9BC3BF"
android:elevation="16dp"
android:text="FERTIG"
android:textColor="#FFFFFF"
android:textStyle="bold"
app:layout_constraintVertical_bias="0.777" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
You need to use a similar layout pattern for title layout and the recycler view item. It's
use
android:weightSum="3"
and for child views set the layout_weight as 1. All three will be aligned.
I have made changes to your code.
RecyclerView Item
<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="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
android:gravity="center">
<TextView
android:id="#+id/order_overview_artikel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Artikel"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="10dp"
android:textSize="16dp"/>
<TextView
android:id="#+id/order_overview_anzahl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anzahl"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="10dp"
android:textSize="16dp"/>
<TextView
android:id="#+id/order_overview_preis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preis"
android:gravity="center"
android:layout_weight="1"
android:textSize="16dp"/>
</LinearLayout>
Your popup
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="15dp">
<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:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Bestellübersicht"
android:textAlignment="center"
android:textSize="25dp"
android:textStyle="bold"></TextView>
<TextView
android:id="#+id/order_overview_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="0"
android:textAlignment="center"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:weightSum="3"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:text="Produkt"
android:layout_weight="1"
android:gravity="center"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="Anzahl"
android:layout_weight="1"
android:gravity="center"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="Preis"
android:layout_weight="1"
android:gravity="center"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
</LinearLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview_order_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.airbnb.lottie.LottieAnimationView
android:layout_width="match_parent"
android:layout_height="128dp"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="#raw/walkingburger" />
<Button
android:id="#+id/btn_order_overview_finish"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:background="#drawable/button_order_checkout"
android:backgroundTint="#9BC3BF"
android:elevation="16dp"
android:text="FERTIG"
android:textColor="#FFFFFF"
android:textStyle="bold"
app:layout_constraintVertical_bias="0.777" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
First of all, in your pop, for "Produkt", "Anzahl" and etc. you write layout_width like "match_parent", but in your RecyclerView layout_width of items is wrap_content. Change layout_width on match_parent in your RecyclerView.
You need a table view layout in order to align texts, you can also use linear layout but it tricky and complex UI solution which performs quite heavy operations on the UI layer to render (example using weights in linear layout).
Check this android official link for more understanding.

Imageview not taking corner radius of cardview

Hi i'm developing an app where i'm using imageview inside cardview but my problem is that imageview somehow is not taking the corner radius applied to cardview
Please see the image below
I tried doing different things but dont understand where the problem is please if anyone can guide me
my xml
<android.support.v7.widget.CardView 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="100dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:id="#+id/cardview2"
app:cardCornerRadius="25dp"
card_view:cardPreventCornerOverlap="false"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageView
android:layout_width="88dp"
android:layout_height="88dp"
android:id="#+id/imageView"
android:scaleX="1.2"
android:scaleType="fitXY"
android:scaleY="1.2"
android:src="#drawable/club1"
android:background="#drawable/corner_radius"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="#+id/nameTextView"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginTop="16dp"
android:maxLines="2"
android:text="Item"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:id="#+id/ratingTextView"
android:layout_marginStart="4dp"
android:drawableEnd="#color/White"
android:drawableRight="#color/White"
android:drawablePadding="2dp"
android:text="4,5"
android:gravity="center"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="12sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
See here is the Image. Remeber Don't make CardView as Main 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="1dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
app:cardUseCompatPadding="true"
android:elevation="0dp"
app:cardCornerRadius="5dp"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_suvichar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/placeholder" />
<TextView
android:id="#+id/tv_suvichar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Title"
android:padding="5dp"
android:textColor="#color/black"
android:textSize="#dimen/normal_text_size" />
</LinearLayout>
</android.support.v7.widget.CardView>
Try Replace your Linear Layout with Relative Layout.
After that set gravity of your last textview (center_horizontal).
You can use the RoundedImageView :
Put this in the build.gradle
compile 'com.makeramen:roundedimageview:2.3.0'
And to use it:
<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
app:riv_corner_radius="5dp"/>
Just use this code in xml and see result after RUN the code:
<android.support.v7.widget.CardView
android:layout_marginTop="100dp"
android:layout_gravity="center_horizontal"
app:cardCornerRadius="20dp"
android:id="#+id/cv"
android:clipChildren="true"
android:layout_width="100dp"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:scaleType="centerCrop"
android:src="#drawable/recipe"
android:layout_width="match_parent"
android:layout_height="100dp" />
<TextView
android:layout_margin="8dp"
android:text="ITEM"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginLeft="8dp"
android:layout_marginBottom="8dp"
android:text="34"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
Try this way :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/_5sdp"
android:layout_marginTop="#dimen/_5sdp"
android:layout_marginLeft="#dimen/_5sdp"
android:layout_marginRight="#dimen/_5sdp"
android:layout_marginBottom="5dp"
cardview:cardCornerRadius="#dimen/_3sdp"
cardview:cardElevation="#dimen/_3sdp"
cardview:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="#dimen/_180sdp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/placeholder"/>
<RelativeLayout
android:padding="#dimen/_5sdp"
android:id="#+id/rlMiddle"
android:layout_below="#+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtPrescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_10sdp"
android:maxLines="3"
android:paddingTop="8dp"
android:textAppearance="#style/TextAppearance.AppCompat.Headline"
android:textSize="#dimen/_16sdp"
android:text="Demo"
android:textStyle="bold"
/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>

Android Align LinearLayout at Bottom not Working

I have this LinearLayout and in it is a Map Fragment and this all works but I cannot get the linear layout to align to the bottom of the screen for some reason. 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="vertical"
tools:context=".MainActivity"
android:baselineAligned="false"
android:weightSum="1"
android:background="#mipmap/background_colour">
<LinearLayout
android:orientation="vertical"
android:layout_width="30dp"
android:layout_height="31dp"
android:weightSum="1"
android:id="#+id/back_button"
android:background="#drawable/navigation_back"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.31">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView7" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.30">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView6" />
</LinearLayout>
<LinearLayout
android:id="#+id/lay"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:layout_weight="3.5">
</LinearLayout>
</LinearLayout>
The LinearLayout I am trying to align is the id: "lay" one.
I found a fix:
<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"
tools:context=".MainActivity"
android:baselineAligned="false"
android:weightSum="1"
android:background="#mipmap/background_colour">
<LinearLayout
android:orientation="vertical"
android:layout_width="30dp"
android:layout_height="31dp"
android:weightSum="1"
android:id="#+id/back_button"
android:background="#drawable/navigation_back"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="177dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView7" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="146dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView6" />
</LinearLayout>
<LinearLayout
android:id="#+id/lay"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="match_parent">
</LinearLayout>
</LinearLayout>

Move Layouts when opening the EditText Keyboard

i'm creating a console or terminal thing, and i'm having a problem. Normaly my Activity looks like this:
but when i click in the edittext and the keyboard opens my edittextfield and my send-button are gone:
but i want the edittext and the sendbutton to be above the keybaord, so you see what you're typing and you're able to send it. This is my xml 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"
android:background="#d1d1d1">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="477dp"
android:layout_below="#+id/title" >>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView"
android:text="Console:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="0dip"
android:gravity="top"
android:textSize="20sp"
android:textColor="#000000"
android:typeface="monospace"
android:paddingLeft="0dp"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<EditText
android:layout_marginLeft="5dp"
android:layout_width="163dp"
android:layout_height="wrap_content"
android:id="#+id/consoleText"
android:layout_weight="0.92" />
<Button
android:layout_width="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
android:text="Send"
android:id="#+id/sendButton"
android:layout_gravity="right" />
</LinearLayout>
</LinearLayout>
Maybe somebody knows, how i can fix this issue! Thanks in advance, any help is appreciated :)
Setting ScrollView's layout_weight=1 should work. Try this
<?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"
android:background="#d1d1d1">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView"
android:text="Console:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="0dip"
android:gravity="top"
android:textSize="20sp"
android:textColor="#000000"
android:typeface="monospace"
android:paddingLeft="0dp"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_marginLeft="5dp"
android:layout_width="163dp"
android:layout_height="wrap_content"
android:id="#+id/consoleText"
android:layout_weight="0.92" />
<Button
android:layout_width="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
android:text="Send"
android:id="#+id/sendButton"
android:layout_gravity="right" />
</LinearLayout>
</LinearLayout>

Layout is squeezing when keyboard appears

My layout is squeezing a little when keyboard pops up.
Here is my xml file
<?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="fill_parent"
android:fillViewport="true"
android:focusable="true"
android:focusableInTouchMode="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10"
android:background="#android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:weightSum=".9"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_weight=".01" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight=".3"
android:paddingLeft="12dp"
android:id="#+id/username"
android:hint="#string/username"
android:textColorHint="#color/edittextcolor"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:hint="#string/password"
android:layout_weight=".3"
android:paddingLeft="12dp"
android:textColorHint="#color/edittextcolor"
android:layout_marginRight="10dp"
android:id="#+id/password" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:weightSum="2"
android:layout_marginTop="30dp">
<Button
android:id="#+id/signup"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/Sign"
android:textColor="#android:color/white"
android:layout_marginLeft="20dp" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/login"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:textColor="#android:color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
The layout is looking good when the keyboard is not appearing.I have added
android:windowSoftInputMode="adjustResize" in the mainifest file.But still it isn't working.
Any help will be much appreciated.Thanks in advance..
Change
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10"
android:background="#android:color/white">
to
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
Hope your problem will be solved.

Categories

Resources