I want to display the grid view elements in only one row that means i want horizontal scrolling in grid view.Each time i want to display only 5 elements only in one row.For this give me some suggestions.Thanks in advance.
below is the my layout code
<?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"
>
<ImageView
android:id="#+id/ImageViewlarge"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</ImageView>
<TextView
android:id="#+id/TextViewImageName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:editable="false">
</TextView>
<LinearLayout
android:layout_width="fill_parent"
android:orientation="horizontal"
android:gravity="bottom" android:layout_height="fill_parent">
<ImageView
android:id="#+id/ImageViewLeft"
android:clickable="true"
android:focusable="true"
android:layout_alignParentLeft="true"
android:src="#drawable/leftarrow" android:layout_height="50sp" android:layout_width="30sp" android:layout_gravity="bottom|left">
</ImageView>
<GridView
android:id="#+id/GridView01"
android:scrollbars="horizontal"
android:layout_height="wrap_content"
android:fadingEdge="horizontal"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:numColumns="5" android:layout_gravity="center_horizontal" android:layout_width="260sp">
</GridView>
<ImageView
android:id="#+id/ImageViewRight"
android:clickable="true"
android:focusable="true"
android:src="#drawable/rightarrow" android:layout_width="30sp" android:layout_height="50sp" android:layout_gravity="right"/>
</LinearLayout>
</LinearLayout>
in that above code now i want to remove the that 2 image view and set the horizontal scroll to that grid view elements.For this give me some suggestions,Thanks in advance
I believe the same effect could be achieved by using a LinearLayout with the orientation set to horizontal. The LinearLayout can be embedded in a HorizontalScrollView
The documentation on HorizontalScrollView actually says this:
A HorizontalScrollView is a
FrameLayout, meaning you should place
one child in it containing the entire
contents to scroll; this child may
itself be a layout manager with a
complex hierarchy of objects. A child
that is often used is a LinearLayout
in a horizontal orientation,
presenting a horizontal array of
top-level items that the user can
scroll through.
Related
I have a xml view like this, and as you see I have scroll view in it, but scroll view doesn't scroll and just match screen size, and I'm not able to see data under the screen.
This is my code:
CODE HAS BEEN UPDATED
<ScrollView
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:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/aboveRelative"
android:background="#color/darkOrange">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/category_text"
android:textSize="23sp"
android:textColor="#color/white"
android:text="Category"
android:paddingLeft="10sp" />
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="200dp"
android:verticalSpacing="0dp"
android:horizontalSpacing="10dp"
android:numColumns="2"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/gray"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/topVoices"
android:textSize="23sp"
android:text="#string/topVoices"
android:paddingLeft="10sp" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/trendlist"
android:elevation="2dp"
android:background="#color/white"
android:layout_margin="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/moreTrend"
android:layout_gravity="right"
android:textSize="23sp"
android:text="More"
android:paddingLeft="10sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/newVoices"
android:textSize="23sp"
android:text="#string/newVoices"
android:paddingLeft="10sp" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/soundlist"
android:background="#color/white"
android:layout_below="#+id/newVoices"
android:elevation="5dp"
android:layout_margin="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/soundlist"
android:id="#+id/moreNew"
android:layout_gravity="right"
android:textSize="23sp"
android:text="#string/more"/>
<LinearLayout
android:id="#+id/yoursongs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:background="#color/white"
android:padding="10dp">
</LinearLayout>
</LinearLayout>
</LinearLayout>
I'm sure that there are some data under the screen but scroll view doesn't let me scroll it and see them.
Scrollview layout can only have ONE child layout. You still have TWO linear layout children in the XML you posted.
This is explained in the first paragraph of the Android developer documentation for ScrollView:
http://developer.android.com/reference/android/widget/ScrollView.html
Your layout is wrong. Here's what you gotta do:
Change your ScrollView layout_height attribute to match_parent.
The ScrollView will take the whole screen and make itself scrollable, that's why you need it as match_parent. The scrolling happens inside the View.
Put everything inside the ScrollView in a Linear or RelativeLayout. (see below)
The ScrollView extends FrameLayout, so it can only have a single child view.
IMPORTANT: this layout must have the attribute layout_height set to wrap_content, otherwise the ScrollView won't have anything larger than itself to scroll.
I'd also remove the root layout from the XML and leave the ScrollView as root.
Simply because it's pointless and it requires extra work from the LayoutInflater.
EDIT: your layout is also way more complex that it needs to be.
It lead me to believe you did not have a single child inside the ScrollView (which you do).
Still, item #1 should fix your problem.
Finally, I found answer. The problem was from fillviewport in scroll view. if you remove fillviewport and set fix size for listview, you can scroll.
I need to have a button, a grid view and a button, arranged vertically. I can see the Button and the GridView but can't see the button declared after the grid view. Why's that? This happens with any view below the grid view declaration.
<?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/text_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="20dip"
android:text="Fragment1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30dip" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button1"/>
<GridView
android:id="#+id/gridview"
android:layout_width="wrap_content"
android:layout_height="match_parent"overla
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button1"/>
</LinearLayout>
As you have taken LinearLayout with vertical orientation, give wrap_content to the height of GridView.
Now, if you want last button at below to the screen, then include android:layout_weight="1" in GridView.
try this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button1"/>
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button1"/>
as you have declared height of gridview as match_parent it should overlap the views declared below it if it can not find enough screen space available to show it.
You should try calling bringtoFront() method on the view declared below gridview.
Other thing from my viewpoint is to try relativeLayout if possible and use android:layout_above and android:layout_below with gridview.
I have an activity which loads a few layouts in a layout.xml file. The First LinearLayout host the all the views together. The second linear layout hosts two labels together. The Relative layout host a few labels and a ListView that populates items when loaded. I want to improve navigation by achieving a "TRANSITION" of the RelativeLayout to another Layout without affecting other layouts in the activity. In other words, when clicking on one of the rows populated by the ListView (OnItemClickListener), this event listener replaces the current RelativeLayout with a new Layout.
Any idea of achieving this?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:background="#FFDECE"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Date"
android:layout_weight="0.5"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gang Code"
android:layout_weight="1.0"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp">
<TextView
android:id="#+id/tvEmpyName"
....
</RelativeLayout>
<ListView
android:id="#+id/lvATRDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
You can use ViewFlipper for that. And use setDisplayedChild(int) to display particular layout i.e. child
e.g.
setDisplayChild(0);
I'm trying to make an Android layout: 3 components inside a vertical LinearLayout. The center component is a ScrollView that contains a TextView. When the TextView contains a significant amount of text (more than can fit on the screen), the ScrollView grows all the way to the bottom of the screen, shows scrollbars, and pushes the last component, a LinearLayout with a Button inside, off the screen.
If the text inside the TextView inside the ScrollView is short enough, the button at the bottom of the screen is positioned perfectly.
The layout I'm trying to achieve is:
The XML for the layout I've written is:
<?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">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip"
android:text="Title />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:textColor="#FFFFFF"
android:background="#444444"
android:padding="10dip" />
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button android:id="#+id/login_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:text="#string/next_button"/>
</LinearLayout>
</LinearLayout>
The scrollview is the second view object and is set to wrap_content, which is more than the screen.
I recommend a RelativeLayout. Top textview first with android:alignParentTop="true", the bottom LinearLayout next with android:alignParentBottom="true" and the scrollview listed last in the xml with the value android:alignBelow="#id/whatYouCallTheHeader.
This will align the bottom bar at the bottom of the screen, and the header at the top, no matter the size. Then the scrollview will have its own place, after the header and footer have been placed.
you should go for relativeLayout rather than LinearLayout. And you can use some properties like alignBelow and all.
Try adding a layout weight into the ScrollView ie.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
This worked for me in a situation almost identical to the one you're presenting but left me wondering why, because it is counter-intuitive that increasing the layout weight of a control from 0 (the default if you don't specify a layout_weight) to 1 should make a control which is already using too much space smaller.
I suspect the reason it works is that by not specifying a layout_weight you actually allow the layout to ignore the size of the scroll view relative to other controls and conversely if do specify one you give it permission to shrink it in proportion to the weights you assign.
![Fixed Header-Footer and scrollable Body layout ][1]
This is what you are looking for . Most of the app in android had this type of layout ,
a fixed header and footer and a scrollable body . The xml for this layout is
<?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:background="#5599DD"
android:layout_height="fill_parent">
<!-- Header goes here -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip"
android:textSize="20sp"
android:layout_gravity="center"
android:text="Title" />
<!-- Body goes here -->
<ScrollView
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="#string/lorem_ipsum"
android:textColor="#FFFFFF"
android:padding="10dip" />
</ScrollView>
<!-- footer goes here -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/login_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="bottom"
android:layout_alignParentRight="true"
android:text="Button"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
How to set footer in android on each page
I have used:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/mcolor"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="fill">
<ImageButton android:id="#+id/iconbtn"
android:layout_height="wrap_content"
android:src="#drawable/all_icon_138"
android:layout_marginRight="4px"
android:layout_gravity="fill"
android:clickable="true"
android:layout_width="wrap_content"
android:background="#color/mcolor"
android:layout_marginLeft="60px"
android:layout_marginTop="12px" android:saveEnabled="true">
</ImageButton>
<TextView android:text="#+id/TextView01"
android:id="#+id/label"
android:textColor="#color/mbcolor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scrollbars="vertical"
android:layout_marginBottom="30px"
android:layout_marginTop="30px"
android:textSize="12px"
android:layout_marginRight="30px"
android:layout_marginLeft="130px"></TextView>
<LinearLayout android:layout_marginTop="50dip"
android:gravity="bottom"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true">
<ImageButton android:id="#+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/newfox_footer_320"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="false"
android:layout_alignParentLeft="false" android:layout_marginLeft="190px" android:layout_marginRight="2px">
</ImageButton></LinearLayout>
</RelativeLayout>
It is showing 6 images of footer after each TextView.
How do I set it?
its is not clear what do you exactly want but i assume you want a footer in a layout.
use a framelayout as you main layout with
width = fillparent
height = fillparent
take another framelayout set the gravity to bottom.
add views to this framelayout.
this is your footer.
Make the root view of your xml Layout a RelativeLayout.
Then the view you want as footer, or his parent (the one who is direct child of the root view element: RelativeLayout) needs to have this attribute:
android:layout_alignParentBottom="true"
You've used LinearLayout for footer, so you can check out stackoverflow: footer for linear layout in android