I am trying to make whole layout scrollable but in this case only listview is being scrolled and not the whole layout. Please tell me how can I make the whole page to be scrolled up and not just the listview in it. Thanks
My XML file
<LinearLayout 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:orientation="vertical" tools:context=".MainActivity"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <GridView android:id="@+id/grid" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerInParent="true" android:columnWidth="100dp" android:gravity="center" android:horizontalSpacing="2dp" android:numColumns="auto_fit" android:paddingTop="2dp" android:stretchMode="columnWidth" android:verticalSpacing="2dp" /> </LinearLayout> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="5dp" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:text="More Devices" android:textStyle="bold" /> <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="3dp" android:paddingLeft="3dp" android:paddingTop="3dp" /> </LinearLayout>
My MainActivity.java
package project.example.com.project;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class MainActivity extends Activity {
GridView grid;
String[] gridtext = {"Text 1", "Text 2", "Text 3", "Text 4", "Text 5", "Text 6", "Text 7", "Text 8", "Text 9"};
int[] gridimage = {R.drawable.img, R.drawable.img, R.drawable.img, R.drawable.img, R.drawable.img, R.drawable.img, R.drawable.img, R.drawable.img, R.drawable.img};
ListView listView;
String[] listtext = {"List 1", "List 2", "List 3", "List 4", "List 4", "List 4"};
int[] listimage = {R.drawable.image, R.drawable.image, R.drawable.image, R.drawable.image, R.drawable.image, R.drawable.image};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list);
CustomGrid adapter = new CustomGrid(MainActivity.this, gridtext, gridimage);
grid = (GridView) findViewById(R.id.grid);
grid.setAdapter(adapter);
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MainActivity.this, "You Clicked at " + gridtext[+position], Toast.LENGTH_SHORT).show();
}
});
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
String[] from = {"txt", "img"};
int[] to = {R.id.list_text, R.id.list_image};
SimpleAdapter simpleAdapter = new SimpleAdapter(getBaseContext(), list, R.layout.list_row, from, to);
for (int i = 0; i < listtext.length; i++) {
HashMap<String, String> hashMap = new HashMap<String, String> ();
hashMap.put("txt", listtext[i]);
hashMap.put("img", Integer.toString(listimage[i]));
list.add(hashMap);
}
listView.setAdapter(simpleAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "You Clicked at " + listtext[+position], Toast.LENGTH_SHORT).show();
}
});
View header = getLayoutInflater().inflate(R.layout.header, null);
listView.addHeaderView(header);
}
}