it's just a simple question:
I have a layout file which is presented as an item inside of a ListView. I set the height of the RelativeLayout to 100dp, but it does not work, it's always wrapping the content, no matter which layout I use. What can I do to set a fixed value to the layout height without having it wrapping?
Thanks for the help.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="100dp"> <!-- this attribute seems to be ignored -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="#dimen/progressbar_small"
android:layout_height="#dimen/progressbar_small"
android:layout_gravity="center_vertical" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/loading"
android:layout_gravity="center_vertical"
style="#style/ListItemSubtext" />
</LinearLayout>
</RelativeLayout>
Do like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="100dip">
I think in a list view all items are of the same height. In your case you could add the progress bar in the list footer view. Add a dummy height adjuster right before or after ListItemSubtext. Try using TableLayout instead of Relative and Linear Layout.
A dummy adjuster is like this.
<View android:layout_width="wrap_content" android:layout_height="100dip"/>
Please note you do not need xmlns in every element.
Try just using 100px. Works for me.
i do below changes in your xml..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="100dp"> <!-- this attribute taking a fixed value as u said -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:layout_width="20dip"
android:layout_height="20dip"/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/loading"
android:layout_gravity="center_vertical"
style="#style/ListItemSubtext" />
</LinearLayout>
If this doesn't work for you, say what exactly you want to do.
Related
I am developing an application in which i am using a custom list view. The XML code is as follows :
<?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:background="#drawable/loginbg" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="15sp"
android:background="#android:color/white" >
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#000000"
android:dividerHeight=".5sp" >
</ListView>
</RelativeLayout>
</RelativeLayout>
And my custom adapter XML is :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="75sp"
android:paddingBottom="75sp"
android:gravity="center"
android:textSize="20sp"
android:textColor="#android:color/white" />
</RelativeLayout>
But my out put is not like what i needed. I needed vertical padding of text which i given in adapter textview in XML.
My out put is:
I need space from top and bottem of text in text view which is in adapter of list view.
I tried from .java file also as :
textView.setPadding(0, 75, 0, 75);
but of no use.
I need output like :
Please guide me what should i do now.
You don't need top and bottom then, check this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textviewn_company_clsa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="75dp"
android:text="asdf"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
For the custom layout, inside your TextView, use marginTop and marginBottom (or layout_margin)which will give you space outside the TextView's container.
Padding provides the space within your container. For your ListView item, you need the space outside each row/item also.
Check:
Android beginner difference between padding and margin
Difference between a View's Padding and Margin
android:paddingTop="75sp"
android:paddingBottom="75sp"
And
android:layout_margin="15sp"
android:dividerHeight=".5sp"
Unit needs to be in "dp"..:
android:paddingTop="75dp"
android:paddingBottom="75dp"
And
android:layout_margin="15dp"
android:dividerHeight=".5dp"
For your ref:
What is the difference between "px", "dp", "dip" and "sp" on Android?
http://www.prandroid.com/2013/03/differences-between-px-dip-dp-and-sp.html
Use this :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dp" >
<TextView
android:id="#+id/textviewn_company_clsa"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textSize="20sp"
android:textColor="#android:color/white" />
</RelativeLayout>
I have a listview that will be filled with AsyncTask and at the bottom edge of the app I need to show a fixed overlay layout like this:
But I can't figure it out how I can do this in xml?
This is my present layout.xml:
<?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">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- Probably I need to do something here -->
</LinearLayout>
As Daniel has suggested, use a RelativeLayout because it allows stacking of components(same with FrameLayout and SurfaceView). The following code will give you the layout you are looking for:
<?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" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/transparentBlack"
android:layout_alignParentBottom="true" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView1"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:text="Medium Text"
android:textColor="#color/white"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="40dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white" />
</RelativeLayout>
</RelativeLayout>
In the code above, the color hex values used for transparentBlack is #95000000 and white is #ffffff.
Here is an excellent tutorial on the basics of UI design in android: Android User Interface Design: Layout Basics.
Change the parent layout to RelativeLayout or FrameLayout and position the fixed view at the same level of the ListView (but after the ListView)
Something like:
---> RelativeLayout
--> ListView
--> Any view as the fixed view
You can then align the fixed view to the bottom of the wrapping RelativeLayout
<?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">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- Here you should position the fixed view -->
</RelativeLayout>
Yes I read this question. No it didn't help.
The problem is that only the highlighted area of my ListView cell is clickable. It is the area that is filled with text. Take a look on the picture:
So when you click on the circled area - it wouldn't respond.
Any ideas on how to make it work properly???
Edit: my list layout:
<?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:padding="5dp">
<ImageView
android:id="#+id/shoulderLogo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp">
</ImageView>
<TextView
android:id="#+id/shoulderLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
I'm pretty sure this is because your list layout LinearLayout has a layout_width of wrap_content. This will cause your row to only be as wide as the views contained within. If you set it instead to fill_parent or match_parent it will extend to fill the width of your list.
Try changing to this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<ImageView
android:id="#+id/shoulderLogo"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp">
</ImageView>
<TextView
android:id="#+id/shoulderLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TextView>
I have made layout for custom dialog, it has inside two imageview. I want to show both Imageview when dialog appear. and i want to hide the main layout of my xml file I have used "#00000000" as background:color, but it is not working.
Is there any way to do the same?
Thanks.
Here is my layout. I have taken screen shot please have a look i want to hide the border which are showing in image.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" android:background="#00000000">
<LinearLayout android:id="#+id/linearLayout1"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<ImageView android:id="#+id/img_closeimage" android:src="#drawable/product_zoom_close"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:clickable="true"></ImageView>
</LinearLayout>
<LinearLayout android:id="#+id/linearLayout2"
android:layout_marginLeft="25dip" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="-5dip" android:layout_marginBottom="20dip" android:layout_marginRight="20dip">
<ImageView android:id="#+id/img_ProductZoom" android:src="#drawable/index"
android:layout_width="wrap_content" android:layout_height="wrap_content"
></ImageView>
</LinearLayout>
</LinearLayout>
image description here
Adinias comment is correct, your layout has quite some redundancy. You also say that you only want to show an imageview, but your layout contains two imageviews. If you only want to show one imageview, then your layout should look like this:
<?xml version="1.0" encoding="utf-8"?>
<ImageView android:id="#+id/img_ProductZoom" android:src="#drawable/index"
android:layout_width="wrap_content" android:layout_height="wrap_content"
/>
If you want to show two ImageViews, use this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" android:background="#00000000">
<ImageView android:id="#+id/img_closeimage" android:src="#drawable/product_zoom_close"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:clickable="true"/>
<ImageView android:id="#+id/img_ProductZoom" android:src="#drawable/index"
android:layout_width="wrap_content" android:layout_height="wrap_content"
/>
</LinearLayout>
Your current layout looks the way it does because you have specified the layout to take as much space as possible with android:layout_height="fill_parent" and android:layout_width="fill_parent". Try to use wrap_content as height and width instead.
I am attempting to put a ListView beneath a Text View in an Android App. However, the first line of the ListView shows up on the same line as the TextView. How do I get this to move underneath?
Here is the layout:
<?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">
<TextView android:id="#+id/android:question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dummy_question" />
<ListView android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/no_notes"/>
</LinearLayout>
I think at first look prob. is only that in linearlayout put
android:orientation=vertical
it will solve ur prob.
Try using a TableLayout. Example. Good luck.
I see two issues. First, as chirag mentioned, you need to set the ListView orientation. Second, a listView cannot 'wrap content' for height. What would it wrap to? One row, two? Basically, a listView has no idea how tall you want it to be. Try this:
<?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/android:question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dummy_question" />
<ListView android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="0px" android:layout_weight="1" />
<TextView android:id="#+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/no_notes"/>
</LinearLayout>