0

i have this layout for my main activity:

<?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/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:contentDescription="@string/my_app"
        android:src="@drawable/logo" />

    <GridView
        android:id="@+id/gridView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:horizontalSpacing="10dp"
        android:numColumns="auto_fit"
        android:paddingBottom="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:verticalSpacing="10dp" >

    </GridView>

    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/about"
        android:textColor="#FFFFFF"
        android:background="#F7921A"
        android:gravity="center"
    />    
</LinearLayout>

I tried to add ScrollView with LinearLayout as its child, but when i run the app the scroll bar is applied to gridview only, showing only one row of the gridview... How to apply scroll bar to the entire screen?

smartmouse
  • 13,912
  • 34
  • 100
  • 166

1 Answers1

1

As far as I understand, you want the GridView to cover a certain part of the screen (presumably the center) and have the TextView at the bottom (fixed), right? If so utilze a relative layout as your root and use android:layout_alignParentBottom="true" for the TextView and android:layout_alignParentTop="true" for the ImageView. You can then align the GridView using android:layout_below="@+id/imageView1" and android:layout_above="@+id/yourTextView".

Update:

<?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="wrap_content"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:src="@drawable/logo"
        android:contentDescription="@string/my_app" />

    <GridView
        android:id="@+id/gridView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/textView1"
        android:layout_below="@+id/imageView1"
        android:horizontalSpacing="10dp"
        android:numColumns="auto_fit"
        android:paddingBottom="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:verticalSpacing="10dp" >
    </GridView>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#F7921A"
        android:gravity="center"
        android:text="@string/about"
        android:textColor="#FFFFFF" />

</RelativeLayout>
siyb
  • 2,837
  • 2
  • 21
  • 18
  • With this GridView disappeared! Anyway i still get the same warning "The vertically scrolling ScrollView should not contain another vertically scrolling widget (GridView)" – smartmouse Jan 07 '15 at 15:00
  • @smartmouse can you please post your current layout? – siyb Jan 07 '15 at 15:01
  • Sure, here is current layout after applying your hints http://pastebin.com/K2jmQCZm – smartmouse Jan 07 '15 at 15:03
  • As I thought, you cannot nest scrollable Views on Android (or at least you shouldn't). The ScrollView as well as the GridView are both scrollable. If you want to have the TextView and the ImageView at the top or the Bottom of your View (and still be scrollable) you have to use headers and footers, please refer to http://stackoverflow.com/questions/13217386/add-a-header-to-a-gridview-android on how to do that. If you are ok with the ImageView and the TextView not scrolling, you can remove the outer ScrollView and lodge the GridView in between the ImageView and the TextView as I suggested. – siyb Jan 07 '15 at 15:09
  • I prefer the the second choice but in this case i can't see the textview at the bottom in devices with small screens. – smartmouse Jan 07 '15 at 15:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/68350/discussion-between-siyb-and-smartmouse). – siyb Jan 07 '15 at 15:22
  • It is acceptable for me, now the image is on top, the text is on bottom (both fixed) and the scroll bar appeared for gridview. So can't i apply scroll bar to entire screen? – smartmouse Jan 07 '15 at 15:22