I know i am doing a small mistake.
I am using LinearLayout and i want to place the "icon-image" at "Center".
I am using the following code:
<LinearLayout
android:id="#+id/LinearLayout01"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0">
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
android:layout_gravity="center_vertical|center_horizontal|center">
</ImageView>
</LinearLayout>
<LinearLayout>
............
</LinearLayout>
</LinearLayout>
As you see above, i have also set layout_gravity.
Now my problem is, if i set android:layout_width="wrap_context" instead of "fill_parent" in Child Linear Layout (i.e. LinearLayout02) then it works fine. but then whats should i do to set icon-image at Center while setting fill_parent?
Pls anybody focus their knowledge and let me help to find out the mistake.
Pls help me.
Thanx,
Paresh
Add this to LinearLayout02 to specify that its contents should be centered horizontally:
android:gravity="center_horizontal"
Related
What's up guys, just a quick question. I'm trying to get my GridView to be center inside it's parent which is a RelativeLayout. I want the entire grid to be centered, not the items. From what I'm seeing, the default alignment is "left-aligned" and it's difficult to change this behavior. I tried a few other solutions suggested in other SO questions found here as well as couple others. This seems like something trivial, and that it shouldn't be such a headache. I tried wrapping the GridView inside a LinearLayout with horizontal orientation but to no avail.
The only semi workaround I've found was to mess around with the left and right padding, but even that approach leaves way too much empty space at the sides.
This image is before I changed the padding
This image is after I messed around with padding, but again..seems a bit hackish and not really what I'm looking for. I'm looking for flush center without the extra padding on the sides
Another reason why this approach is impractical is due to the extra space, the selector appears to be too large..as seen in the image below
Any help on this would great, thanks as always!
Code for the layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/weatherFragRoot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<GridView
android:id="#+id/menuGridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/weathermate_lv_background"
android:gravity="center_horizontal"
android:listSelector="#drawable/list_selector"
android:numColumns="3"
android:paddingLeft="30dp"
android:paddingRight="5dp"
android:stretchMode="columnWidth"
android:visibility="invisible" >
</GridView>
</RelativeLayout>
EDIT
As suggest by user, I centered each grid item row inside it's own relative layout..and that gave me the result I was looking for! Here is the updated XML files to reflect the solution
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/weatherFragRoot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<GridView
android:id="#+id/menuGridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/weathermate_lv_background"
android:gravity="center_horizontal"
android:listSelector="#drawable/list_selector"
android:numColumns="3"
android:stretchMode="columnWidth"
android:visibility="invisible" >
</GridView>
</RelativeLayout>
This is the layout for the grid row. As you can see, what worked for me was setting the orientation to Horizontal and adding android:layout_centerHorizontal="true" to each child.
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="#+id/menuItem"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:background="#android:drawable/ic_menu_add" >
</ImageView>
<TextView
android:id="#+id/tvMenuItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/menuItem"
android:layout_centerHorizontal="true"
android:text="Option"
android:textColor="#android:color/white" >
</TextView>
</RelativeLayout>
The answear is to center image and text views in each grids as they have separate layout :)
I follow this link https://github.com/harism/android_page_curl now I want to modify size of the curlview,I already try to change android:layout_width="fill_parent" android:layout_height="fill_parent" in main.xml file but it is not working.
So, Please tell me How to change curlView height,width and background.
Thanks
For width and height change, you could put that custom view in a Linear Layout and change Linear Layout properties like below.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="50dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_weight="1"
android:orientation="vertical" >
<com.mobinius.hungama.curl.CurlView
android:id="#+id/curl"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
For background color
mCurlView.setBackgroundColor(0xFF202830);
I have asked this question before but didn't get a "good enough" answer.
My problem basically is that I can't get Admob to show correctly in a ListActivity.
My layout looks like 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"
xmlns:myapp="http://schemas.android.com/apk/res/se.javalia.myDrinks"
android:orientation="vertical">
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<ListView android:id="#+id/android:list" android:layout_alignParentTop="true"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<TextView android:id="#+id/android:empty"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="#string/main_no_items" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" >
<com.admob.android.ads.AdView android:id="#+id/ad"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent" android:layout_height="wrap_content"
myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
myapp:keywords="drink alcohol wiskey rum soda" myapp:refreshInterval="300" />
</LinearLayout>
</RelativeLayout>
The problem right now is that if I change the layout_hight to fill_parent or attempt a value larger than 150 px the ad wont show. With a layout_hight of 150 or less it shows nicely. The goal is to get the list to fill the screen after the ad has taken its place.
Any suggestions? I'm quite lost about how to solve this.
I will update the question if the answer didn't get all the way so please check for updates.
Thanks in advance
Roland
Use one RelativeLayout as the outer wrapper and set your listview to parent top and your adview to parent bottom.
I had this problem and was very difficult to find answers in internet. But i had luck, and I found an answer that worked for me.
Please remove in your code android:layout_height="wrap_content" and add these two new lines into your Listview
android:layout_height="0dip"
android:layout_weight="1"
Your Listview code should look like this
<ListView
android:id="#+id/android:list"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
I hope that works for you.
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.
I hope can get the layout like this:
-----Search bar(EditTextview)---
-----Listview(Rows)--------
-----Bottom bar(Contain many buttons)---
Pls give many samples
Thanks very much
I paste my xml file here.Pls help me check it:
Here's a layout from one of my apps, should be enough to get you started:
<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="#+id/list_view"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_weight="0"
android:gravity="bottom">
<!-- Buttons go here -->
</LinearLayout>
</LinearLayout>
Search for layout_weight to get an idea of how it works.
within your linearlayout, use Relativelayout for each edittext,listview and footer.
in footer layout set android:orientation="horizontal" it works.