how to set height of layouts - android

friend's,
i have a problem in setting height of layout,i have three layout with seperate xml layout,
1.header.xml
it have an textview
2.main.xml have frmelayout with listview
3.content.xml
it have field to bind in framelayout listview.
i need to know how to increase the height of the header as much i need,
here my code for getting solution
Actually i'm facing problem here isi have gallery of menus in header ,whrn iplace this gallery view below header i'm getting it with hidded below half of the gallery,because the height of header can't being changed in any sense,
here the code for header.xml
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:background="#drawable/gradient_black"
android:layout_gravity="center_horizontal" android:layout_width="fill_parent"
android:orientation="horizontal">
<ImageView android:src="#drawable/image_button1" android:id="#+id/back"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true"/>
<TextView android:id="#+id/header_text1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="#+id/back"
android:textSize="20sp" android:textStyle="bold" android:textColor="#color/white"
android:layout_marginLeft="60dip" android:layout_centerVertical="true"
android:layout_centerHorizontal="true" android:ellipsize="end"
android:singleLine="true" />
<ImageView android:src="#drawable/image_button" android:id="#+id/share"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="#+id/header_text1" android:paddingTop="10dip"
android:paddingLeft="50dip" />
<Gallery android:id="#+id/gv" android:layout_width="fill_parent" android:paddingTop="0dip"
android:layout_height="fill_parent" android:spacing="15dip"
android:layout_below="#+id/back"
android:gravity="bottom" android:paddingBottom="0dip"/>
</RelativeLayout>
here the code for main.xml it have an FrameLayout have listview,have tab host and linearlayout at top
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="200dip" android:id="#+id/main_lay">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="100dip"
android:layout_marginTop="100dip">
<ListView android:id="#+id/content_listview"
android:layout_width="fill_parent" android:layout_height="340dip" />
</FrameLayout>
.
.
.
</LinearLayout>
----
</TabHost>
==================== code for list content field
it have linerlayout with three field to set on list...
===== here code for my activity
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.header);
. ;.---- help me get the clear view of gallery in header without hidding at bottom or simply how can i increase height of header layout.

As WarrenFaith said, we can't help you without the XML code. The basic answer with the informations you gave is layout_height but you can have set fill_parent and layout_weight to other fields and it would not be the same. Please provide some code

#MGSenthil: everybody was once new here. Simply work with and not against us :)
Back to topic: What do you mean with because the height of header can't being changed in any sense? Please clarify if you cant change the height because it didnt work or if you cant change it because it has to be this size?!
If you want to have this header with a specific size, you should consider to remove something of the content so it fits.
I never used a custom title, but you should check if its not better to request NO_TITLE and simply add your header to the main.xml layout? You should be able to increase the height of your header that way.

Related

My included layout doesn't fill the whole space when I set the visibility with View.GONE

I don't know if it's the right way to do this but I hope you'll be able to help me.
I'm using a ListActivity to display content from RSS feed. While the content is loading I want to display a pending view. I'm using the EndlessAdapter from that website https://github.com/commonsguy/cwac-endless. It provides a way to display a pending view but the first time it loads data it's a tiny row in an empty list so it's not very sexy.
I'm actually trying to fix this up with this method :
A custom layout for my ListActivity where there is a pending view that I can hide or show for the first loading. The XML code of the layout is like 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="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:cacheColorHint="#FFFFFF"/>
<include
android:id="#+id/progressBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
layout="#layout/loading_anim">
</include>
</LinearLayout>
The first time I load data I set the list visibility to gone with this line :
listView.setVisibility(View.GONE);
It's almost working but the included layout doesn't fill the entire screen and right know I don't know how to fix this in a proper way.
Hope someone will be able to help me, thank's!
UPDATE :
I tried to set the contentview with only the loading layout (see XML below) and I got the same result (see http://imageshack.us/photo/my-images/594/loadingwf.png/) :
this.setContentView(R.layout.loading_anim);
<?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="fill_parent"
android:background="#FFFFFF"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="5dp" >
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="#string/loading" />
</LinearLayout>
So I'm wondering if maybe it's because of the tabs... Can anybody help me ? Thank's
UPDATE 2
I found a solution, it had nothing to do with the neverending adapter. See The content of my tabs doesn't fill the whole space
In your ListView, try this:
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:cacheColorHint="#FFFFFF"/>
What I did was set layout_height to wrap_content. Should fill your entire screen now.

Problems with custom spinner alignment and width

I've created a custom spinner using my own ProjectSpinnerAdapter. I've also got another class which just inflates the layout but hasn't been implemented yet so is still using the standard spinner.
I can't seem to get my custom spinner to align the same way as the standard spinner.
I'm also having problems when the length of the item is wider than the table cell as you can see below. Is there not a way to truncate the options if they are over a certain length ? - This doesn't seem like its the correct way to fix this but I can't directly set the width of the widget as this is controlled via the table layout.*
**Fixed, See update*
Screenshots
The standard spinner aligns perfectly with the Button it sits next to (they are both contained within the same TableRow)
layout
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1" >
<TableRow>
<Button
android:id="#+id/selectButton"
android:text="#string/show" />
<Spinner android:id="#+id/projectSpinner" />
</TableRow>
spinner_list_item.xml (Uses maxLength)
<?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"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title_text_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:maxLength="15"
android:gravity="center"/>
</LinearLayout>
Update
The issue was the layout of the spinner item, in my custom layout spinner_list_item.xml I'd specified a layout all I needed was the textview
spinner_list_item.xml (Uses maxLength)
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title_text_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:maxLength="15" />
If I may ask, why did you choose the TableLayout? I think the same could be achieved with a RelativeLayout and layout_toRightOf layout_below, etc. Or a LinearLayout with a weightSum and gravity each child having a layout_weight.
I'm not going to give you a solution that changes your entire layout though ;), but I tested this and this seems to work for me.
<TableRow>
<Button
android:id="#+id/selectButton"
android:maxLength="10"
android:text="sdadadasdfffffffffffffffffffffffff"/>
<Spinner
android:id="#+id/projectSpinner"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true" />
</TableRow>
Hopefully this works and it's a better way than setting a fixed string length
edit
I'm not sure why you're populating the spinner the way you are, but you can try:
<?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="wrap_content"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:maxLength="15"/>
</RelativeLayout>
android:gravity is wrong too, needs to be android:layout_gravity (but that's LinearLayout only
Last edit :D
try using the default layouts
view = vi.inflate(android.R.layout.spinner_list_item, null);
then
((TextView) view.findViewById(R.id.text1)).setText(title);

How do I set the position of an image view in a relative layout in Android?

I'm trying to position an image below a TextView in a RelativeLayout but it doesn't work. when i set its position using android:layout_below. This is my xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#ccc"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/app_details_1"
android:text="#string/app_details_1"
android:textColor="#347"
android:gravity="center"
android:textSize="9pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/logo"
android:src="#drawable/secs"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/appdetails_1" <!-- I'm setting it here -->
/>
</RelativeLayout>
Instead it just places the image at the top left of the screen. How do I position it? Is layout_below a wrong positioning code?
There's a mistake in your xml. Must be
android:layout_below="#id/app_details_1"
it should be ok, but first try to make sure the textView is positioned on top by using layout_alignParentTop="true" for the textView and see if it does the trick.

Unable to populate listview with custom rows when component is above listview

I'm having issues with a ListView using custom rows that are loaded from a database.
If, for the list screen, I place a button above the ListView, no visible rows appear in the listview.
However as soon as I remove the button, everything works fine. I want the button (or any other component) to appear above to make it more user friendly. Attached are the two code samples below.
This is the XML file of the ListView Activity that works:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/real_red_dark">
<LinearLayout
android:id="#+id/llMain"
android:layout_height="fill_parent"
android:background="#drawable/real_background"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:gravity="center">
<ListView
android:id="#+android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/llButton"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/no_sessions"
android:textStyle="bold"
android:textSize="18dp"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
However, if I have the Button added above it, it will not show whatsoever:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/real_red_dark">
<LinearLayout
android:id="#+id/llMain"
android:layout_height="fill_parent"
android:background="#drawable/real_background"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:gravity="center">
<Button
android:id="#+id/btnSearch"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:layout_gravity="center_horizontal"
android:layout_marginTop="3dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:text="Find Sessions"
android:textStyle="bold" />
<ListView
android:id="#+android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/llButton"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/no_sessions"
android:textStyle="bold"
android:textSize="18dp"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
You could try adding the button programmatically as a header view in the listview itself, rather than in the xml layout.
use listView.addHeaderView(View)
http://developer.android.com/reference/android/widget/ListView.html#addHeaderView(android.view.View)
It is better if you use RelativeLayout than LinearLayout,it is also recommended by the android docs.Try to use android:layout_height value as "wrap_content" for ListView and TextView(which you may use to indicate for empty rows),it may help to you.
Something which doesn't look right but I'm assuming it's just a typo in the above...
android:id="#+android:id/list"
...there shouldn't be a + between # and android:. Using #+ is for adding a new resource id of your own, i.e., #+id:. You're also doing the same thing for the TextView...
android:id="#+android:id/empty"
Another thing but not sure it's relevant is you're specifying...
android:layout_below="#+id/llButton"
...I doubt it's the problem as android:layout_below isn't valid for a LinearLayout (it's for RelativeLayout) but there isn't a Button with the id of llButton in your layout. If there was, the + would also be incorrect as you should be specifying an existing id.
Not sure if amending the above would fix things but it could just be that the layout inflation is coming out 'wrong' due to those issues.

Crashes whenever I try to use a custom view object in XML layout

I have made myself a custom LinearLayout by the name of com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget that hosts a couple of spinner widgets. This custom LinearLayout inflates the following XML layout (You might not need to look at this too carefully but it's here for completeness):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- Min value Spinner -->
<Spinner
android:id="#+id/discrete_numerical_range_selector_min_value_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_weight="1" />
<TextView
android:id="#+id/to_text"
android:text="to"
android:textSize="14sp"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_weight="0">
</TextView>
<!-- Max value Spinner -->
<Spinner
android:id="#+id/discrete_numerical_range_selector_max_value_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1" />
I have placed one such object in the layout for one of my activities like so:
<?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="fill_parent"
android:orientation="vertical">
<include layout="#layout/search_form_section_generic_top"/>
<include layout="#layout/search_form_section_car_specific"/>
<com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget/>
<include layout="#layout/search_form_section_advanced_options" />
</LinearLayout>
The problem is that my app force closes immediately upon startup. I've checked by putting breakpoints in my custom LinearLayout that none of my custom code is even being run yet. Furthermore, if I copy-paste the layout code for my compound widget in place everything works, which indicates to me that I probably haven't left any important XML attributes out. What could be going wrong?
I fixed it by making the LinearLayout XML element in the widget layout into a merge instead, and moved all of the layout parameters out of the widget XML file and into the activity XML itself, thus replacing
<com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget/>
with
<com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
If someone could tell me why this worked, it might help me and others doing it again, and you can take credit.
because you must specify the width and height of every view you use in you xml?

Categories

Resources