In my android app I have created two TextView inside CardView layout. The first TextView will show the description of one item and second TextView will show a link of that item. but whenever I run my app, the second text is overlapping with the first one. I want to implement in such a way that after finishing the first text the second one with start. but I fail to implement that.
Here is my code for CardView layout.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/news_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/large_text"/>
<TextView
android:id="#+id/webLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/link"
android:layout_gravity="bottom"
android:textAppearance="?android:attr/textAppearanceSmall" />
</android.support.v7.widget.CardView>
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/news_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/large_text"/>
<TextView
android:id="#+id/webLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/link"
android:layout_gravity="bottom"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
make your layout like this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/news_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/large_text" />
<TextView
android:id="#+id/webLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="#string/link"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
Use the RelativeLayout or LinearLayout inside the CardView like this:
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/news_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dklfjkdsjfsd"
/>
<TextView
android:id="#+id/webLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/news_description"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Hope this will help you out.....
You have put two TextViews inside CardView. The super class of CardView is FrameLayout. Putting your TextVeiws inside a LinearLayout or Relative Layout can solve your problem.
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/news_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/large_text"/>
<TextView
android:id="#+id/webLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/link"
android:layout_gravity="bottom"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</android.support.v7.widget.CardView>
Related
I want to add a switch or checkbox button to a fragment layout. When i add it, it loads the layout until the checkbox comes, and it kinda "destroy" the layout, mixing it with the previous layout fragment.
I tried using switch and checkbox and it messes up, using another textview instead it works fine.
Here is a photo with switch in xml: Image with switch
As you can see, the left margin is cutted and at his bottom there are elements from previous layout, and they are not clickable.
Here is a photo with a textview instead of the switch element: image without switch
Here, the layout works perfectly.
Here is the xml layout, with a not simple structure for creating the layout i wanted. At the bottom of the layout file, you can see the switch element, which i think it ruins the entire layout.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/tools"
android:background="#E8E8E8"
app:ignore="NamespaceTypo">
<!-- Here you put the rest of your current view-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
>
<android.support.design.card.MaterialCardView
android:id="#+id/acquisto_cardview_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardElevation="2dp"
android:layout_margin="8dp"
card_view:cardCornerRadius="5dp"
card_view:strokeColor=" #696969"
card_view:strokeWidth="1dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp">
<android.support.v7.widget.CardView
android:id="#+id/acquisto_cardview_info_intestazione"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/acquisto_cardview_info_intestazione_text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/info_intestazione"
android:background="#drawable/textview_sottolineato"
style="#style/italictext_summary"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/acquisto_cardview_info_tot_articoli"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_below="#id/acquisto_cardview_info_intestazione"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/acquisto_cardview_info_tot_articoli_txt_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/info_totale_articoli"
style="#style/acquisto_card_textview"
android:layout_alignParentStart="true"
android:ellipsize="end"
/>
<TextView
android:id="#+id/acquisto_cardview_info_tot_articoli_txt_prezzo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
style="#style/acquisto_card_textview"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/acquisto_cardview_info_punti_guadagnati"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_below="#id/acquisto_cardview_info_tot_articoli"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/acquisto_cardview_info_punti_guadagnati_txt_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/info_punti_guagnati"
style="#style/acquisto_card_textview"
android:layout_alignParentStart="true"
android:ellipsize="end"
/>
<TextView
android:id="#+id/acquisto_cardview_info_punti_guadagnati_txt_prezzo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
style="#style/acquisto_card_textview"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</android.support.design.card.MaterialCardView>
<android.support.design.card.MaterialCardView
android:id="#+id/acquisto_cardview_impo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardElevation="2dp"
android:layout_margin="8dp"
card_view:cardCornerRadius="5dp"
card_view:strokeColor=" #696969"
card_view:strokeWidth="1dp"
android:layout_below="#id/acquisto_cardview_info"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp">
<android.support.v7.widget.CardView
android:id="#+id/acquisto_cardview_impo_intestazione"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/acquisto_cardview_impo_intestazione_text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/impo_intestazione"
android:background="#drawable/textview_sottolineato"
style="#style/italictext_summary"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/acquisto_cardview_impo_carta_addebitata"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_below="#id/acquisto_cardview_impo_intestazione"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/acquisto_cardview_impo_carta_addebitata_txt_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/impo_carta_addebitata"
style="#style/acquisto_card_textview"
android:layout_alignParentStart="true"
android:ellipsize="end"
android:layout_toStartOf="#id/acquisto_cardview_impo_carta_addebitata_txt_prezzo"
/>
<TextView
android:id="#+id/acquisto_cardview_impo_carta_addebitata_txt_prezzo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Visa :x 5748"
style="#style/acquisto_card_textview"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/acquisto_cardview_impo_sconto_disponibile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_below="#id/acquisto_cardview_impo_carta_addebitata"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/acquisto_cardview_impo_sconto_disponibile_txt_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/impo_sconto_disponibile"
style="#style/acquisto_card_textview"
android:layout_alignParentStart="true"
android:ellipsize="end"
/>
<TextView
android:id="#+id/acquisto_cardview_impo_sconto_disponibile_txt_prezzo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
style="#style/acquisto_card_textview"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/acquisto_cardview_impo_applica_sconto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_below="#id/acquisto_cardview_impo_sconto_disponibile"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--inserire checkbox qui-->
<Switch
android:id="#+id/acquisto_cardview_impo_applica_sconto_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/impo_checkbox_sconto"
style="#style/acquisto_card_textview"
android:layout_alignParentStart="true"
android:ellipsize="end"
android:textOn="#string/on"
android:textOff="#string/off"
android:layoutDirection="rtl"
app:switchPadding="16dp"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</android.support.design.card.MaterialCardView>
<android.support.design.card.MaterialCardView
android:id="#+id/acquisto_cardview_finale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardElevation="2dp"
android:layout_margin="8dp"
card_view:cardCornerRadius="5dp"
card_view:strokeColor=" #696969"
card_view:strokeWidth="1dp"
android:layout_below="#id/acquisto_cardview_impo"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp">
<android.support.v7.widget.CardView
android:id="#+id/acquisto_cardview_finale_intestazione"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/acquisto_cardview_finale_intestazione_text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/finale_intestazione"
android:background="#drawable/textview_sottolineato"
style="#style/italictext_summary"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/acquisto_cardview_finale_totale_ordine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_below="#id/acquisto_cardview_finale_intestazione"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/acquisto_cardview_finale_totale_ordine_txt_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/finale_totale_ordine"
style="#style/acquisto_card_textview"
android:layout_alignParentStart="true"
android:ellipsize="end"
android:layout_toStartOf="#id/acquisto_cardview_finale_totale_ordine_txt_prezzo"
/>
<TextView
android:id="#+id/acquisto_cardview_finale_totale_ordine_txt_prezzo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
style="#style/acquisto_card_textview"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/acquisto_cardview_finale_bottone_acquisto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_below="#id/acquisto_cardview_finale_totale_ordine"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</android.support.design.card.MaterialCardView>
</RelativeLayout>
</ScrollView>
Please help me, i dont know what's happening here.
Use ConstraintLayout root view group for your layout.
You will get at least 2 positive things:
You will remove "view to view" side effects.
You will have flatten layout with better performance.
i'm trying to make a layout_below the cardview in relative layout but it wont show up in my device where layout_above works. i dont know why it wont work. i think it should be work because it below the cardview. please help what did i miss or wrong.
this is my xml code
<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:background="#drawable/background_2"
tools:context=".ExchangeFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/saldo"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/holder" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="Will Stitch"
android:textSize="15dp"
android:textStyle="bold" />
</LinearLayout>
<android.support.v7.widget.CardView
android:id="#+id/saldo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Saldo"
android:textColor="#color/colorPrimary"
android:textSize="20dp"
android:textStyle="bold" />
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/saldo"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="WillStitch#gmail.com"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
please help why it like this
It is working but your ImageView take all the width and it don't have android:src attribute (so it show nothing) and you don't need the last LinearLayout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/saldo"
android:orientation="vertical">
<!-- Useless Linear Layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="WillStitch#gmail.com"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
I have the following xml. Basically I want to display the movie overview below the Layout whose id is equals to layoutOne.
<ScrollView 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:scrollbarStyle="outsideOverlay">
<LinearLayout
android:id="#+id/layoutOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:padding="16dp"
android:background="#color/primary"
>
<ImageView
android:id="#+id/movie_image"
android:layout_width="160dp"
android:layout_height="240dp"
android:scaleType="fitXY"
android:layout_gravity="center_vertical"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:padding="16dp"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content">
<TextView
android:id="#+id/movie_title"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
/>
<TextView
android:layout_below="#+id/movie_title"
android:layout_centerHorizontal="true"
android:id="#+id/movie_rating"
android:text="9/10"
android:textSize="24sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_below="#+id/movie_rating"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_marginTop="13dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/ic_menu_my_calendar"/>
<TextView
android:layout_below="#+id/movie_rating"
android:layout_centerHorizontal="true"
android:id="#+id/movie_date"
android:text="2017-10-9"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
/>
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/title_overview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Great movie" />
</LinearLayout>
</ScrollView>
Here is what I get.
I want the sample text Great movie to be below that light pink layout. The tricky part here is that Scrollbar view allow only one child view. Any ideas?
Thanks,
Theo.
The Constraint of the RelativeLayout should fit the whole page. If you want to use ScrollView you should add the RelativeLayout to the ScrollView too.
Hence it would be like this :
<LinearLayout
android:id="#+id/layoutOne"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:padding="16dp"
android:background="#color/primary"
>
Later you can use the following to adjust the image:
<LinearLayout
android:layout_marginBottom="439dp"
android:layout_marginEnd="156dp"
android:layout_marginStart="156dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
Hi I have parent layout as LinearLayout and I need to place an imageview at center and after that two textview one after another at center of screen. At bottom of the screen is an icon.
I placed everything but imageview and two textview are not aligning at center of screen. Here is 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="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/bg"
android:orientation="vertical">
//this image and two textview, i need to place at center of screen
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/seat_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/on_logo"
android:layout_marginBottom="#dimen/dp_size20"
/>
<TextView
android:id="#+id/seat_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test1"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp"
android:gravity="center"/>
<TextView
android:id="#+id/another_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/dp_size10"
android:paddingBottom="#dimen/dp_size10"
android:text="TEst 2"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp"
android:gravity="center"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/dp_size10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<ImageView
android:id="#+id/on_boarding_circle_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:background="#drawable/circle_arrow" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
I really couldn't figure out what mistake I am doing in this design. ImageView, and two text are placing at top of screen and not in center of screen.
I have changed some dimensions and images, correct those and you are good to go.
try this..
<?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:background="#drawable/bg">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerInParent="true"
android:orientation="vertical">
<ImageView
android:id="#+id/seat_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#mipmap/ic_launcher"
android:layout_marginBottom="20dp" />
<TextView
android:id="#+id/seat_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test1"
android:textAllCaps="false"
android:textSize="16dp"
android:gravity="center"/>
<TextView
android:id="#+id/another_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/dp_size10"
android:paddingBottom="#dimen/dp_size10"
android:text="TEst 2"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp"
android:gravity="center"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="#dimen/dp_size10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<ImageView
android:id="#+id/on_boarding_circle_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:background="#mipmap/ic_launcher" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<LinearLayout
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:id="#+id/seat_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
/>
<TextView
android:id="#+id/seat_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test1"
android:textAllCaps="false"
android:textColor="#color/Grey"
android:textSize="16dp"
android:gravity="center"/>
<TextView
android:id="#+id/another_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="TEst 2"
android:textAllCaps="false"
android:textSize="16dp"
android:gravity="center"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<ImageView
android:id="#+id/on_boarding_circle_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:background="#drawable/acircle" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
The problem is that you are using linear layout so it is aligning the layouts one after another.So you need to use relative layout and it will work
Try this code
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/bg"
android:orientation="vertical">
//this image and two textview, i need to place at center of screen
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/seat_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/on_logo"
android:layout_marginBottom="#dimen/dp_size20"
/>
<TextView
android:id="#+id/seat_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test1"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp"
android:gravity="center"/>
<TextView
android:id="#+id/another_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/dp_size10"
android:paddingBottom="#dimen/dp_size10"
android:text="TEst 2"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="16dp"
android:gravity="center"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/dp_size10">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<ImageView
android:id="#+id/on_boarding_circle_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:background="#drawable/circle_arrow" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
The RelativeLayout at the bottom is the problem. And add android:gravity="center" to your parent LinearLayout
Just add android:gravity="center" in your root LinearLayout and remove last RelativeLayout and see
cut the 'layout_gravity' and 'gravity' parameters from child LinearLayout and paste this to Parent LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/seat_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Your code....
>
I want to create layout which looks like this:
Name1, Something1, OtherThing and Name2 are TextViews (each one of them is clickable with different action) which are added do parent layout programmatically. Sometime there too much elements to fit in one line. Which layout as parent should I use to let TextViews be placed horizontally but with possibility to "break line"? Horizontal LinearLayout isn't working.
try to use FlowLayout:
FlowLayout is an layout that display its children in multiple rows
depending on their size.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="STUFF"
android:textSize="30dp"/>
</LinearLayout>
<com.wefika.flowlayout.FlowLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Something1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OtherThing" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name2" />
</com.wefika.flowlayout.FlowLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="MORE STUFF"
android:textSize="30dp"/>
</LinearLayout>
</LinearLayout>
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">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="STUFF"
android:textSize="30dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Something1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OtherThing" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name2" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="MORE STUFF"
android:textSize="30dp"/>
</LinearLayout>