Horizontal ScrollView in Android Studio - java

<?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">
<HorizontalScrollView
android:id="#+id/hsv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="An"
android:id="#+id/textView1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Codificare
Disciplina"
android:layout_marginLeft="10dp"
android:id="#+id/TexView2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Denumire"
android:layout_marginLeft="10dp"
android:id="#+id/TexView3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Curs"
android:layout_marginLeft="10dp"
android:id="#+id/TexView4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Seminar"
android:layout_marginLeft="10dp"
android:id="#+id/textView5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Laborator"
android:layout_marginLeft="10dp"
android:id="#+id/TexView6"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Proiect"
android:layout_marginLeft="10dp"
android:id="#+id/TexView7" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar Credite"
android:layout_marginLeft="10dp"
android:id="#+id/TexView8" />
</TableRow>
</TableLayout>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
I can't add multiple rows in this table because i got errors like SrollView can hold only one parent at once and when i try to solve it the row goes vertically in column. Please help me.
I just tried all the solutions and i can't make it works. I don't know why i tried to solve this with solution find on stackoverflow and sites like this but i can't.

You are setting height = 0dp in your rows. Change this
android:layout_height="0dp"
to this:
android:layout_height="wrap_content"
Tested with 2 rows, all worked as aspected for me:
<?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">
<HorizontalScrollView
android:id="#+id/hsv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="An"
android:id="#+id/textView1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Codificare
Disciplina"
android:layout_marginLeft="10dp"
android:id="#+id/TexView2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Denumire"
android:layout_marginLeft="10dp"
android:id="#+id/TexView3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Curs"
android:layout_marginLeft="10dp"
android:id="#+id/TexView4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Seminar"
android:layout_marginLeft="10dp"
android:id="#+id/textView5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Laborator"
android:layout_marginLeft="10dp"
android:id="#+id/TexView6"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Proiect"
android:layout_marginLeft="10dp"
android:id="#+id/TexView7" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar Credite"
android:layout_marginLeft="10dp"
android:id="#+id/TexView8" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="An"
android:id="#+id/textView21" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Codificare
Disciplina"
android:layout_marginLeft="10dp"
android:id="#+id/TexView22"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Denumire"
android:layout_marginLeft="10dp"
android:id="#+id/TexView23" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Curs"
android:layout_marginLeft="10dp"
android:id="#+id/TexView24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Seminar"
android:layout_marginLeft="10dp"
android:id="#+id/textView25" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Laborator"
android:layout_marginLeft="10dp"
android:id="#+id/TexView26"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar ore
Proiect"
android:layout_marginLeft="10dp"
android:id="#+id/TexView27" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Numar Credite"
android:layout_marginLeft="10dp"
android:id="#+id/TexView28" />
</TableRow>
</TableLayout>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
What's your problem?

May be you should try this :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent">
<HorizontalScrollView
android:id="#+id/hsv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fillViewport="true"
android:measureAllChildren="false"
android:scrollbars="none" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceLarge"
android:text="An"
android:id="#+id/textView1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceLarge"
android:text="CodificareDisciplina"
android:layout_marginLeft="10dp"
android:id="#+id/TexView2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceLarge"
android:text="Denumire"
android:layout_marginLeft="10dp"
android:id="#+id/TexView3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceLarge"
android:text="Numar oreCurs"
android:layout_marginLeft="10dp"
android:id="#+id/TexView4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceLarge"
android:text="Numar oreSeminar"
android:layout_marginLeft="10dp"
android:id="#+id/textView5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceLarge"
android:text="Numar oreLaborator"
android:layout_marginLeft="10dp"
android:id="#+id/TexView6"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceLarge"
android:text="Numar oreProiect"
android:layout_marginLeft="10dp"
android:id="#+id/TexView7" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceLarge"
android:text="Numar Credite"
android:layout_marginLeft="10dp"
android:id="#+id/TexView8" />
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/hsv"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Caca"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_margin="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Caca"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_margin="10dp"
/>
</TableRow>
</RelativeLayout>
i add this after my code, another row appear but when i move LinearLayout and Scrollview the enhance all code my text goes on first row at the end. I tried all that you told me but doesn't work.

Related

Android layout design : Using LinearLayout and Relative layout

I want to have a layout exactly similar to one below in image.
I've tried the below code but it is not coming.
Can someone help me in getting this layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<TextView
android:id="#+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Ali Connors"
android:textSize="12sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/firstLine"
android:gravity="center_vertical"
android:text="Brunch this weekend?"
android:textSize="16sp" />
<TextView
android:gravity="right"
android:id="#+id/rightTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="15m"
android:textSize="16sp" />
</RelativeLayout>
try the following:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="#ED262A" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp">
<TextView
android:id="#+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="26dp"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Ali Connors"
android:textSize="18sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/firstLine"
android:gravity="center_vertical"
android:text="Brunch this weekend?"
android:textSize="15sp" />
<TextView
android:id="#+id/thirdLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/secondLine"
android:drawablePadding="6dp"
android:drawableRight="#android:drawable/star_off"
android:gravity="center_vertical"
android:text="I will be in the place"
android:textColor="#A4A18E"
android:textSize="14sp" />
<TextView
android:id="#+id/rightTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentRight="true"
android:gravity="top|right"
android:text="15m"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
Try this.
<TextView
android:text="15m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/rightTime"
android:textSize="16sp"/>
Design your Layout as below:
<?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"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="#FF4081" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="#+id/rightTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="15m"
android:textSize="14sp"
android:textColor="#727272"/>
<TextView
android:id="#+id/firstLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/rightTime"
android:layout_marginRight="8dp"
android:maxLines="1"
android:ellipsize="end"
android:text="Ali Connors"
android:textSize="16sp"
android:textColor="#000000"/>
<TextView
android:id="#+id/secondLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/firstLine"
android:layout_marginTop="2dp"
android:text="Brunch this weekend?"
android:textSize="16sp"
android:textColor="#000000"
android:maxLines="1"
android:ellipsize="end" />
<ImageView
android:id="#+id/image_star"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_below="#id/secondLine"
android:layout_alignParentRight="true"
android:background="#android:drawable/star_big_off" />
<TextView
android:id="#+id/thirdLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/secondLine"
android:layout_toLeftOf="#id/image_star"
android:layout_marginTop="4dp"
android:layout_marginRight="16dp"
android:text="I will be in your neighborhood doing some errands....."
android:textColor="#727272"
android:textSize="14sp"
android:maxLines="1"
android:ellipsize="end" />
</RelativeLayout>
</LinearLayout>
Output:

How do you arrange ImageViews and TextViews dynamically to Linear Layout in Android?

I've got a fragment from which users select features their rooms have (fig.1 below) and these are stored in the back-end as boolean values i.e. true if set and false otherwise.
The XML for the fragment:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
<!-- none core xml formatting and views -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:weightSum="1"
android:layout_gravity="center_horizontal"
android:background="#drawable/border_bottom_top"
android:id="#+id/details_amenities_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_bic_imageview"
android:src="#mipmap/ic_bic"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_bic_amenity"
android:id="#+id/add_room_bic_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_below="#+id/add_room_bic_imageview" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_entrance_imageview"
android:src="#mipmap/ic_entrance"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_entrance_amenity"
android:id="#+id/add_room_entrance_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_toilet_imageview"
android:src="#mipmap/ic_toilet"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_toilet_amenity"
android:id="#+id/add_room_toilet_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_kitchen_imageview"
android:src="#mipmap/ic_kitchen"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_kitchen_amenity"
android:id="#+id/add_room_kitchen_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:layout_marginTop="8dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_parking_imageview"
android:src="#mipmap/ic_parking"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_parking_amenity"
android:id="#+id/add_room_parking_label"
android:textSize="16sp"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="#+id/add_room_parking_imageview" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_wifi_imageview"
android:src="#mipmap/ic_wi_fi"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_wifi_amenity"
android:id="#+id/add_room_wifi_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_secure_imageview"
android:src="#mipmap/ic_secure"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_secure_amenity"
android:id="#+id/add_room_secure_label"
android:textSize="16sp"
android:gravity="center"
android:layout_below="#+id/add_room_secure_imageview"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:id="#+id/add_room_furnished_imageview"
android:src="#mipmap/ic_furnished"
style="#style/amenities_image_style"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_furnished_amenity"
android:id="#+id/add_room_furnished_label"
android:textSize="16sp"
android:gravity="center"
android:layout_below="#+id/add_room_furnished_imageview"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:layout_marginTop="5dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_borehole_imageview"
android:src="#mipmap/ic_borehole"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_borehole_amenity"
android:id="#+id/add_room_borehole_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_prezesa_imageview"
android:src="#mipmap/ic_zesa"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_zesa_amenity"
android:id="#+id/add_room_prezesa_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/add_room_prezesa_imageview"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_wardrobe_imageview"
android:src="#mipmap/ic_wardrobe"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_wardrobe_amenity"
android:id="#+id/add_room_wardrobe_label"
android:textSize="16sp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="38dp"
android:id="#+id/add_room_prewater_imageview"
android:src="#mipmap/ic_prewater"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/add_room_water_amenity"
android:id="#+id/add_room_prewater_label"
android:textSize="16sp"
android:gravity="center"
android:layout_below="#+id/add_room_prewater_imageview"
android:layout_alignRight="#+id/add_room_prewater_imageview"
android:layout_alignEnd="#+id/add_room_prewater_imageview"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<!-- none core views -->
<android.support.design.widget.FloatingActionButton android:id="#+id/add_room_step3_fab"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end"
android:src="#mipmap/ic_done_white_48dp"
android:layout_marginBottom="#dimen/fab_margin" />
</LinearLayout>
</ScrollView>
Naturally the selected features differ thus the number of views is not constant obtained from the back-end. I am able to retrieve the set features and instantiate the correct views in Java i.e. if there are 5 set features comprising BIC, Wifi, Kitchen etc, I am able to determine these and set the necessary Image resources and Text.
Question now is how do I arrange the views obtained to replicate the layout above using Java code as I can only know the features set after querying the back-end. Desired end result has to look like the image below. Hope it makes sense.

Android Listview SecondLine row

Im new to android development and trying to learn what i don't
get is how i can style the XML below.
All tips and help are very welcome.
I have the following ListView XML
I want to create the following XML
Current XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/LOC_IMAGE"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:width="38dp"
android:gravity="left"
android:src="#drawable/ondergrondse2" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:width="60dp"
android:gravity="center"
android:id="#+id/LOC_CODE" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:width="60dp"
android:gravity="center"
android:id="#+id/LOC_FRACTIE" />
<TextView
android:id="#+id/LOC_NAME"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Niet aanwezig"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:textSize="15dp"
android:width="330dp"
android:layout_marginRight="20dp" />
</LinearLayout>
I want the LOC_NAME TextView under the others ImageVIew And TextView like the picture below
Why downvoting im trying to learn something
You need nested linearlayouts, try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/LOC_IMAGE"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:width="38dp"
android:gravity="left"
android:src="#drawable/ondergrondse2" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:width="60dp"
android:gravity="center"
android:id="#+id/LOC_CODE" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:width="60dp"
android:gravity="center"
android:id="#+id/LOC_FRACTIE" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/LOC_NAME"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Niet aanwezig"
android:layout_marginTop="10dp"
android:layout_marginLeft="35dp"
android:textSize="15dp"
android:width="330dp"
android:layout_marginRight="20dp" />
</LinearLayout>
</LinearLayout>
Do like this,just nest the widget
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="fill_parent">``
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/ImageView01"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:gravity="left"
android:src="#drawable/ondergrondse2"
android:width="38dp" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:width="60dp" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:width="60dp" />
</LinearLayout>
<TextView
android:id="#+id/LOC_NAME"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:text="Niet aanwezig"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="15dp"
android:width="330dp" />
</LinearLayout>
</LinearLayout>
LinearLayouts Order ther ChildViews in a linear way if you want them to be ordererd Verticaly you should change the android:orientation="horizontal"
to android:orientation="vertical", this wil align your views verticaly from top to bottom so to achieve what you want tou shoud do this
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/LOC_IMAGE"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:width="38dp"
android:gravity="left"
android:src="#drawable/ondergrondse2" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:width="60dp"
android:gravity="center"
android:id="#+id/LOC_CODE" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:width="60dp"
android:gravity="center"
android:id="#+id/LOC_FRACTIE" />
</LinearLayout>
<TextView
android:id="#+id/LOC_NAME"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Niet aanwezig"
android:layout_marginTop="10dp"
android:layout_marginLeft="35dp"
android:textSize="15dp"
android:width="330dp"
android:layout_marginRight="20dp" />
</LinearLayout>

Android ListView Row has a frame

This XML is for a ROW in a custom listview. It seems to have an Invisible FRAME, I can't seem to be able to get rid of it and make row fill parent.
I would like the end result to be nothing but Rows, and not able to see background of layer below.
Thank you for reading, XML:
<?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"
android:orientation="vertical"
android:padding="10dp">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#ff515152"
android:layout_alignParentTop="true"
android:id="#+id/relativeLayout"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="140dp"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView2"
android:textSize="25dp"
android:textColor="#fffff7fd"
android:gravity="center_vertical|right"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/textView"
android:layout_toStartOf="#+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:textColor="#fffff7fd"
android:layout_gravity="center_horizontal"
android:text="AND"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:id="#+id/textView" />
<TextView
android:layout_width="140dp"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/group_name"
android:textSize="25dp"
android:textColor="#fffff7fd"
android:gravity="center_vertical|right"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/textView"
android:layout_toEndOf="#+id/textView" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffb7bcb5"
android:layout_below="#+id/relativeLayout"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView3"
android:layout_gravity="center_horizontal"
android:layout_alignParentLeft="false"
android:layout_marginLeft="0dp"
android:layout_alignParentTop="false"
android:layout_marginTop="0dp"
android:layout_centerHorizontal="true"
android:textSize="17dp"
android:textColor="#fffff7fd" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView4"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/textView3"
android:layout_toStartOf="#+id/textView3"
android:textSize="17dp"
android:textColor="#fffff7fd" />
</RelativeLayout>
</RelativeLayout>

Admob integration in my app

I'm trying to add admob into my android app, but I keep having this error in eclipse:
Element type "com.admob.android.ads.AdView" must be followed by either attribute specifications,
">" or "/>".
The code is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.example.SampleApp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.admob.android.ads.AdView android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"</com.admob.android.ads.AdView>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00BFFF"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/txt_stupnjevi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txt_grad"
android:layout_below="#+id/txt_grad"
android:layout_marginTop="5dp"
android:textColor="#FFF"
android:textSize="40sp" />
<ImageView
android:id="#+id/img_glavna"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout1"
android:layout_below="#+id/txt_stupnjevi"
android:layout_centerHorizontal="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:adjustViewBounds="true"
android:src="#drawable/img01d" />
<TextView
android:id="#+id/txt_grad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/img_glavna"
android:layout_alignParentTop="true"
android:textColor="#FFF"
android:textSize="35sp" />
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
android:visibility="gone" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:baselineAligned="false"
android:weightSum="3" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_dan1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:maxLength="3"
android:paddingTop="10dp"
android:textColor="#FFF"
android:textSize="20sp" />
<ImageView
android:id="#+id/img_dan1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/img01n" />
<TextView
android:id="#+id/txt_stupnjevi1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:paddingBottom="10dp"
android:textColor="#FFF"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_dan2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:maxLength="3"
android:paddingTop="10dp"
android:textColor="#FFF"
android:textSize="20sp" />
<ImageView
android:id="#+id/img_dan2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/img11d" />
<TextView
android:id="#+id/txt_stupnjevi2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_dan3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:maxLength="3"
android:paddingTop="10dp"
android:textColor="#FFF"
android:textSize="20sp" />
<ImageView
android:id="#+id/img_dan3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/img13n" />
<TextView
android:id="#+id/txt_stupnjevi3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:textColor="#FFF"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/txt_stupnjevi"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/txt_grad"
android:layout_marginRight="16dp"
android:orientation="vertical"
android:weightSum="3" >
<TextView
android:id="#+id/txt_tlak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:drawablePadding="10dip"
android:drawableRight="#drawable/e2"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFF"
android:textSize="18sp" />
<TextView
android:id="#+id/txt_vlaznost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:drawablePadding="10dip"
android:drawableRight="#drawable/d1"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFF"
android:textSize="18sp" />
<TextView
android:id="#+id/txt_brzina"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:drawablePadding="10dip"
android:drawableRight="#drawable/wind"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFF"
android:textSize="18sp" />
</LinearLayout>
<TextView
android:id="#+id/txt_stanje"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:textColor="#FFF"
android:textSize="18sp" />
</RelativeLayout>
What I should do to solve this?
i got this error too:
The markup in the document following the root element must be well-formed.
Just replace
<com.admob.android.ads.AdView android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"></com.admob.android.ads.AdView>

Categories