I have two questions.
The first, when i load the activity first item of gallery is in the middle. How to ask android to align it to left? (actually i used align="left" but it seems doesn't work)
the second, my activity includes three items, header, body and footer. currently the footer (gallery) is on top of body. I want bottom of body stays on above of footer instead of behind of footer.
any suggestions appreciated. The image is like this.
the code:
<?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"
android:background = "#drawable/bg" >
<!-- Loading header of this UI which is coded separately -->
<include
android:id="#+id/header"
layout="#layout/header_bar" />
<GridView
android:id="#+id/news_gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:numColumns="2"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:layout_below="#id/header"
android:layout_centerInParent="true" />
<Gallery
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
For 1st:
Check this existing SO question:
android gallery image position problem
For 2nd:
- You need to include android:layout_above="#+id/gallery" in your GridView.
- Remoev android:layout_centerInParent="true"
In short, define:
<GridView
android:id="#+id/news_gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dip"
android:numColumns="2"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:layout_below="#+id/header"
android:layout_above="#+id/gallery"/>
Related
I have a GridView within FrameLayout as shown below:
As seen, numbers are aligned closer to left side of the screen. I have tried to bring numbers closer so that i could solve the problem, but failed. Playing around with stretchMode like 'columnWidth' and 'none' couldn't solve my problem. Please suggest me any way that i can fit numbers within background white area.
.xml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/paperbck"
android:columnWidth="30dp"
android:gravity="center"
android:horizontalSpacing="20dp"
android:numColumns="4"
android:stretchMode="columnWidth"
android:verticalSpacing="20dp" />
</FrameLayout>
</LinearLayout>
Try giving left margin to the Grid View.
How to center GridView on the screen.I have GridView with 4 items as 2 items per row. I try to center the GridView inside the Relative layout using padding in relative layout. But I developed application for multiple screens.So I think hardcoded padding is not good practice. How to center this Grid view on mulitple screens?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/gridrelativelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="60dp"
android:paddingBottom="60dp"
android:paddingLeft="150dp"
android:paddingRight="150dp"
tools:context=".MainMenuActivity" >
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F9F9F9"
android:gravity="center"
android:horizontalSpacing="50dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="50dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
Updated Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/gridrelativelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="150dp"
android:paddingRight="150dp"
tools:context=".MainMenuActivity" >
<GridView
android:id="#+id/gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnWidth="20dp"
android:background="#FF0000"
android:gravity="center"
android:horizontalSpacing="50dp"
android:numColumns="2"
android:verticalSpacing="50dp"
android:layout_centerInParent = "true"
/>
</RelativeLayout>
This updated code centers gridView on screen properly. But see,I hardcoded padding for left ad Right in Relative layout.As I want to support to multiple scrrens, I want to make this padding as dynamic using following code.But It not works.
RelativeLayout gridrelativelayout = (RelativeLayout)findViewById(R.id.gridrelativelayout);
int pad=gridrelativelayout.getWidth()/3;
gridrelativelayout.setPadding(pad, 0, pad, 0);
Apply RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
and For GridView
android:layout_centerInParent = "true"
Use android:layout_centerInParent = "true" for GridView. This surely works...
If want write best app to multiple screen devices, so you need read this:
Supporting Multiple Screens
and it is very useful to you:
Supporting Different Screens
Use
android:layout_centerHorizontal = "true"
for GridView.
I want to make Activity like this using GridView.
And this Activity have only one scrollbar include all text & gridview.
for it, using scrollview.
<ScrollView>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<GridView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<GridView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
I wrote xml and class like attached using ScrollView to have only one
scroll.
GridView has android:layout_height="fill_parent", but just visible one row.
And each GridView has scroll.
Same result layout_height was changed to wrap_content.
Is it bug? or Do I have some mistake? or Is it impossible?
Thanks.
You need to use the parameter weight :
0 for TextView
1 for GridView
I'm trying to integrate ads (admob) into my Android app. It's mostly working, except for one issue with the layout. My layout consists of:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res/com.example.photos">
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/status_layout">
<ImageView android:id="#+id/cardStatus"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="#string/hello"
android:id="#+id/cardStatusText" />
</LinearLayout>
<GridView android:id="#+id/imageGridView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="10dp" android:verticalSpacing="10dp"
android:horizontalSpacing="10dp" android:numColumns="auto_fit"
android:columnWidth="100dp" android:stretchMode="columnWidth"
android:gravity="center" android:layout_below="#id/status_layout" />
<!-- Place an AdMob ad at the bottom of the screen. -->
<!-- It has white text on a black background. -->
<!-- The description of the surrounding context is 'Android game'. -->
<com.admob.android.ads.AdView android:id="#+id/ad"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" app:backgroundColor="#000000"
app:primaryTextColor="#FFFFFF" app:secondaryTextColor="#CCCCCC"
app:keywords="Android Photo" />
</RelativeLayout>
The ads are shown at the bottom of the screen, just as I want. However, they seem to be overlayed or drawn on top of the bottom portion of the grid view. I would like the gridview to be shorter, so that the ad can fill the bottom portion of the screen, and not hide part of the gridview. The problem is most annoying when you scroll all the way to the bottom of the gridview, and you still cannot fully see the last row items in the grid due to the ad.
I'm not sure if this is the standard way that AdMob ads work. If this is the case, adding some padding to the bottom of the grid (if that's possible) would due the trick. That way the user can scroll a bit further, and see the last row in addition to the ad.
I just switched from using LinearLayout to RelativeLayout after reading some similar issues with ListViews. Now my ad is along the bottom instead of above the grid, so I'm getting closer.
Thoughts?
-Kevin
put this property in your gridview
android:layout_above="#+id/ad"
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.