Reputation: 17591
In my app I'm creating a Listview inside a RelativeLayout at the centre of the screen. This RelativeLayout is in the centre of the screen end inside there is an ImageView ad background and the ListView.
This is the result that I want to obtain:
and this is the result that I obtain:
The red color is the background color of ListView, so you can see its size.
My activity xml is
<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="#70000000"
tools:context="com.example.example.RecordActivity">
<RelativeLayout
android:id="@+id/content_record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/back_record"
android:layout_centerInParent="true"/>
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:dividerHeight="0dp"
android:divider="@null"
android:background="#70000000">
</ListView>
</RelativeLayout>
</RelativeLayout>
and my adapter layout is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="row"
android:padding="20dip"
android:layout_centerInParent="true"
android:textSize="22dip"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/line"
android:layout_centerInParent="true"/>
</LinearLayout>
what's wrong? How can I obtain the result in first picture?
Thanks
Upvotes: 0
Views: 253
Reputation: 1201
Change height and width of content_record
RelativeLayout
to match_parent
to show in full screen.
EDIT:: Give Specific width to listview
<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="#70000000"
tools:context="com.example.example.RecordActivity">
<RelativeLayout
android:id="@+id/content_record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background:"@drawable/back_record">
<ListView
android:id="@+id/listView"
android:layout_width="750dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:dividerHeight="0dp"
android:divider="@null"
android:background="#70000000">
</ListView>
</RelativeLayout>
</RelativeLayout>
Upvotes: 0
Reputation: 3389
Do this to clean it up some
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_record"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#70000000"
tools:context="com.example.example.RecordActivity">
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:dividerHeight="3dp"
android:divider="@android:color/black"
android:background="@drawable/back_record" />
</RelativeLayout>
A background of #700000000 seems a bit odd, is there a reason for it? And is it the background for everything in your app? If so, you might consider setting your app theme's background to @color/main_background and adding a color xml of <color name="main_background">#70000000</color>
.
Upvotes: 0
Reputation: 637
change your activity xml to:
<?xml version="1.0" encoding="utf-8"?>
<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="#70000000"
tools:context="com.example.example.RecordActivity">
<FrameLayout
android:id="@+id/content_record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/back_record"
android:layout_centerInParent="true"/>
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:dividerHeight="0dp"
android:divider="@null"
android:background="#70000000">
</ListView>
</FrameLayout>
or remove the imageView and set the background of listView to
android:background="@drawable/back_record"
Upvotes: 1