How to align Two TextViews next to each other in LinnearLayouts? - java

I am trying to put two TextViews next to each other but somehow I can't get it to work. I wanted to have the following: txtViewAddress: txtAddress
I've tried putting android:layout_toRightOf="#id/txtViewAddress"
I also tried putting layout_toLeftOf, but both did not work.
Hope you guys can help me out. Thanks in advance.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/CalendarID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="480dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/txtViewAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address: "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="22dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/txtAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/txtViewAddress"
android:text="Hello"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="22dp"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="horizontal">
<Button
android:id="#+id/btn_update"
android:layout_width="45dp"
android:layout_height="35dp"
android:layout_marginRight="5dp"
android:layout_marginTop="100dp"
android:background="#drawable/edit"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="" />
<Button
android:id="#+id/btn_delete"
android:layout_width="38dp"
android:layout_height="24dp"
android:layout_marginRight="5dp"
android:layout_marginTop="100dp"
android:background="#drawable/delete"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="" />
</LinearLayout>
</LinearLayout>

If you need views inside a linear layout next to each other, the orientation of your layout must be horizontal.
You can also use the constraint layout, it has much more flexibility in placing view on your screen.

android:layout_toRightOf="#id/txtViewAddress" is atrribute part of Relative Layout
Use this code
<LinearLayout
android:layout_width="480dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/txtViewAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address: "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="22dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/txtAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/txtViewAddress"
android:text="Hello"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="22dp"
android:textStyle="bold"/>
</LinearLayout>

<LinearLayout
android:layout_width="480dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/txtViewAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address: "
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="22dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/txtAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/txtViewAddress"
android:layout_weight="1"
android:text="Hello"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="22dp"
android:textStyle="bold"/>
</LinearLayout>
change the android:orientation="vertical" to android:orientation="horizontal"
and you can also use android:weightSum="2" weightSum is used to define the priority of the view
if you give equal weight to all views inside linear layout then all the views take on equal amount of space inside the Linear Layout

this should be like following
<LinearLayout
android:layout_width="480dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
.....
......
.....
</LinearLayout>
and also I suggest that do not give fix width to layout instead you set it releted to screen size

Related

Android/XML: RelativeLayout design

basically, I don't understand how to use RelativeLayout. I don't know how to design it. I always use LinearLayout with Table inside of it. Now I use RelativeLayout for my design. I want to know, how to add text "Sorry, no list available" Below is my current code of XML
<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:id="#+id/haha"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MyHistoryList">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:gravity="center"
android:longClickable="false"
android:maxLines="1"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<TextView
android:id="#+id/tvSuggestion"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".80"
android:gravity="start"
android:text="Suggestion"
android:textAllCaps="true"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/colorAccent"
android:textStyle="bold"
app:fontFamily="#font/anaheim" />
<TextView
android:id="#+id/tvStatus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".20"
android:gravity="start"
android:text="Status"
android:textAllCaps="true"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/colorAccent"
android:textStyle="bold"
app:fontFamily="#font/anaheim" />
</TableRow>
</LinearLayout>
<RelativeLayout
android:id="#+id/huhu"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recylcerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:visibility="gone" />
<ImageView
android:id="#+id/imgEmpty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:src="#drawable/empty"/>
</RelativeLayout>
</LinearLayout>
This is how it looks like
(source: fbcdn.net)
But, I want to add text "Sorry, no list available" below of the image (marginTop = 20dp). Can anyone help?
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_below="#id/imgEmpty"
android:text="Sorry, no list available"/>
Insert it below your ImageView of RelativeLayout!
Replace your Relative layout with this.
<RelativeLayout
android:id="#+id/huhu"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recylcerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:visibility="gone" />
<ImageView
android:id="#+id/imgEmpty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:src="#drawable/empty"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_below="#id/imgEmpty"
android:text="Sorry, no list available"/>
Add this below imgEmpty. Use android:layout_below to place the text below image,android:layout_centerInParent="true" to move text to center.
<TextView
android:layout_marginTop="20dp"
android:layout_centerInParent="true"
android:text = "Sorry, no list available"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imgEmpty"/>
Here the output
in relative layout you can use below/above to put view below/above its sibling
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imgEmpty"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:text="TextView"/>

Rearrange RelativeLayout child through java code in android

I'm working on a currency converter app. Everything is working fine. I'm using Nested Linear and Relative Layouts in my xml file. I have arranged the layouts one above the other in RelativeLayout like this. (SIMPLE IDEA)
--------------RelativeLayout----------
------FirstRow------
------Divider-------
-----secondRow------
--------------/RelativeLayout/----------
I've set the divider below firstRow and then secondRow below divider in xml. Now i want to rearrange the rows like this.
--------------RelativeLayout----------
------secondRow------
------Divider-------
-----firstRow------
--------------/RelativeLayout/----------
I'm trying to do like this divider below secondRow and firstRow below divider. but its giving me circular dependencies error. I know all about circular dependencies and i believe the java code is not reseting the above layoutparams, instead its something like merging the two layouts which will definitely shoot circular dependencies error.
XML CODE
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/firstRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/namelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/img"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/ic_sampleicon" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="#dimen/activity_horizontal_margin"
android:orientation="vertical">
<TextView
android:id="#+id/name"
style="#style/TextLableMyTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/brand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#f7f7f7" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/tvpoints"
style="#style/TextCurrencyMyTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/firstRow"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:orientation="horizontal">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_centerInParent="true"
android:background="#drawable/background_gradient_light" />
<ImageView
android:id="#+id/switcherImg"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:src="#drawable/ic_settings"
android:tint="#f7f7f7" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/secondRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/divider"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_cash"
android:tint="#ffe100" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="#dimen/activity_horizontal_margin"
android:orientation="vertical">
<TextView
android:id="#+id/name2"
style="#style/TextLableMyTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Riyal" />
<TextView
android:id="#+id/brand2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#f7f7f7" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/tv"
style="#style/TextCurrencyMyTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="0.0" />
</RelativeLayout>
</RelativeLayout>
Java Code to update params
RelativeLayout.LayoutParams _firstRowParams =
(RelativeLayout.LayoutParams)_firstRow.getLayoutParams();
_firstRowParams.addRule(RelativeLayout.BELOW, R.id.divider);
RelativeLayout.LayoutParams _dividerParams =
(RelativeLayout.LayoutParams)_divider.getLayoutParams();
_dividerParams.addRule(RelativeLayout.BELOW, R.id.secondRow);
/* _firstRow.setLayoutParams(_firstRowParams);
_divider.setLayoutParams(_dividerParams);*/
Try adding below code:
RelativeLayout.LayoutParams _secondRowParams =
(RelativeLayout.LayoutParams)_secondRow.getLayoutParams();
_secondRowParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
_secondRowParams.removeRule(RelativeLayout.BELOW);
Try with above code. It worked for me. You need to remove previous Below rule to avoid circular dependency.
As #Luksprog have mentioned about removing the existing rules before adding the new ones this code snippet will work.
RelativeLayout.LayoutParams _firstRowParams =
(RelativeLayout.LayoutParams)_firstRow.getLayoutParams();
_firstRowParams.removeRule(EXISIING_RULE)//RelativeLayout.Below or RelativeLayout.Above or any other
_firstRowParams.addRule(RelativeLayout.BELOW, R.id.divider);
RelativeLayout.LayoutParams _dividerParams =
(RelativeLayout.LayoutParams)_divider.getLayoutParams();
_dividerRowParams.removeRule(EXISIING_RULE)//RelativeLayout.Below or RelativeLayout.Above or any other
_dividerParams.addRule(RelativeLayout.BELOW, R.id.secondRow);

Center button in a LinearLayout

I just want to center "CenterButton" (center of the root LinearLayout) but Androids just not cooperating..
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_weight="0.00"
android:padding="5dp"
android:background="#zegerg"
android:id="#+id/LinearLayout1">
<ImageView
android:id="#+id/ImageView1"
android:layout_height="match_parent"
android:layout_width="151dp"
android:src="#mipmap/image_1"
android:contentDescription="#string/abcdef"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:id="#+id/CenterButton"
android:layout_gravity="center_horizontal|center_vertical|center"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text !"
android:id="#+id/TextView"
android:paddingBottom="30dp"
android:textColor="#37a52c" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ProgressBar"
android:paddingBottom="30dp"
android:progressTint="#37a52c" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_text"
android:id="#+id/Button2"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>
Tried putting it at the end of the XML but doesn't work because the other elements push it aside.. not really sure what's happening.
if you want to have all three first level children to be in equally-sized columns, then you need to add to all of them the followings attribute:
android:layout_width="0dp"
android:layout_weight="1"
(don't forget the dimension "dp" to the width parameter, otherwise the IDE will complain).
...
<ImageView
android:id="#+id/ImageView1"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:src="#mipmap/image_1"
android:contentDescription="#string/abcdef"/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button"
android:id="#+id/CenterButton"
android:layout_gravity="center_horizontal|center_vertical|center"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:padding="20dp">
....
EDITED:
If you want your CenterButton to overlap all the other views, then what you have to do is:
wrap everything in a relative layout with height equal to 200dp, as its first child
remove the button CenterButton from the current position and add it at the bottom of everything, still inside the relative layout, but below the linear layout
add those properties to the button to make it center in the parent
android:layout_centerInParent="true"
So finally you will have something like this (I have changed some resources):
<?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="200dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_weight="0.00"
android:padding="5dp"
android:background="#android:color/holo_orange_dark"
android:id="#+id/LinearLayout1">
<ImageView
android:id="#+id/ImageView1"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:src="#drawable/plus"
android:contentDescription="abcdef"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text !"
android:id="#+id/TextView"
android:paddingBottom="30dp"
android:textColor="#37a52c" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ProgressBar"
android:paddingBottom="30dp"
android:progressTint="#37a52c" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text"
android:id="#+id/Button2"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Button"
android:id="#+id/CenterButton"
android:layout_gravity="center_horizontal|center_vertical|center"/>
</RelativeLayout>
You can use weight for such purposes for child items. Make layout_width for all of them as 0dp and set layout_weight as 1.
Give the three children in the topmost linear layout a gravity of 1 and a width of 0.
It's not clear what exactly is your problem. However, here are some general notes :
To center a View or a Layout inside RelativeView use layout_centerInParent="true"
To make a Layout on top of other layouts use FrameLayout
The order of the views/layouts in your xml file is important. The one you write the last will be on the top (in our example : the FrameLayout or just the CenterButton should be written after the other views and layouts in your xml file)
To distribute the available space inside LinearLayout among its views use android:layout_weight="1" (change the value according to your needs)
you can play aground with this example :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="200dp">
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#fff"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/ImageView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:src="#mipmap/ic_launcher" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical">
<TextView
android:id="#+id/TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="30dp"
android:text="Text !"
android:textColor="#37a52c" />
<ProgressBar
android:id="#+id/ProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="30dp"
android:progressTint="#37a52c" />
<Button
android:id="#+id/Button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text_text" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<Button
android:id="#+id/CenterButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical|center"
android:text="Button" />
</FrameLayout>
</RelativeLayout>

Gray line inside cardview :)?

How do I remove the gray line (you can see on the screen) at the bottom of CardView?
Archive with source-code
I reviewed everything. I don't understand what the problem is.
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="contact det"
android:gravity="center_vertical"
android:textColor="#android:color/background_dark"
android:textSize="14dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
<View
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="#color/accent"
android:layout_below="#+id/linearLayout"/>
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:gravity="center_vertical"
android:textSize="10dp"
android:layout_below="#+id/linearLayout"
android:layout_alignLeft="#+id/txtSurname"
android:layout_alignStart="#+id/txtSurname"/>
<TextView
android:id="#+id/txtSurname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Surname"
android:gravity="center_vertical"
android:textSize="10dp"
android:layout_below="#+id/txtName"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<TextView
android:id="#+id/txtEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textSize="10dp"
android:layout_above="#+id/txtAdd"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<TextView
android:id="#+id/txtAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textSize="10dp"
android:layout_alignTop="#+id/txtSurname"
android:layout_alignLeft="#+id/txtEmail"
android:layout_alignStart="#+id/txtEmail"/>
</RelativeLayout>
Its my item CardView.
when
card_view:cardCornerRadius="2dp"
all is good, but when I write another value and line appears!
Just use “com.google.android.material.card.MaterialCardView” it will avoid issues connected to CardView
Try this -
android:divider="#null"
Or from your code -
getListView().setDivider(null);
getListView().setDividerHeight(0);

How to create custom item for ListView

I have made custom .xml layout for ListView. Now it looks:
But it isn't good, because I have fixed width of layout (250px):
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="250px">
<ImageView
android:background="#FFFFFF"
android:layout_marginLeft="20px"
android:layout_marginTop="25px"
android:layout_height="100px"
android:layout_width="100px"
android:id="#+id/imageView1" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<TextView
android:layout_marginTop="20px"
android:textStyle="bold"
android:textColor="#FF8C00"
android:layout_marginLeft="20px"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textViewFilmName"
android:layout_width="wrap_content"
android:text="TextView"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_width="fill_parent">
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:text="Director:"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:layout_marginLeft="20px"
android:layout_marginTop="10px"
android:layout_height="wrap_content" />
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textViewDirector"
android:layout_width="wrap_content"
android:layout_marginLeft="2px"
android:text="TextView"
android:layout_marginTop="10px"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView2"
android:layout_marginTop="10px"
android:layout_marginLeft="20px"
android:layout_width="wrap_content"
android:text="Stars:"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:layout_height="wrap_content" />
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textViewStart"
android:layout_width="wrap_content"
android:text="TextView"
android:layout_marginLeft="2px"
android:layout_marginTop="10px"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
If I don't set fixed size for root layout, that I have got similar:
Code for this like previous example, but "250px" have been changed on "fill_layout". How can I set non-fixed size for element, that he will be shown correctly and will fill all row? Thank you
Change the android:layout_height attribute on your outermost layout to "wrap_content" and also for the next LinearLayout (linearLayout2). Then it will work.

Categories

Resources