<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" <TextView android:id="@+id/tv_test" android:text="Test " android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ListView android:id="@+id/list_test" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/tv_test" ></ListView> </RelativeLayout>
And everything is in a ScrollView, i don't know why but the relative layout seems to set a wrap content. And it makes the ListView small and not taking the whole place.
I don't know if it's useful but here's my java code :
public class ShowView extends Activity{
ListView lv;
ArrayAdapter<String> adapter;
String[] myList = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Height", "Nine", "Ten"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.show);
lv = (ListView) findViewById(R.id.list_test);
adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, myList);
adapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
lv.setAdapter(adapter);
}
}
I think you ScrollView is not filling the entire screen. Use this inside scrollView
android:fillViewport="true"
Replace the RelativeLayout
with a vertical LinearLayout
, and set android:layout_weight="1"
and android:layout_height="wrap_content"
on your ListView:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/tv_test"
android:text="Test "
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/list_test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_below="@id/tv_test" />
</LinearLayout>
Check out this article for further information on layout weights.
Also, I would remove the ScrollView
altogether. ListView
manages scrolling itself, and you will run in to all kinds of problems if you embed it inside a container which handles scrolling. If you want to scroll @is/tv_test
along with your ListView
content, then consider putting it inside your ListView
as a header. If you want it to remain static when the ListView
scrolls, then keep it outside the ListView
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With