我的列表项出现在页面的底部,我的意思是,最后一项位于屏幕底部,而其他项则建立在它之上。我希望屏幕顶部的第一个项目和其他项目被放置在第一个之后,一个接一个。我怎样才能做到这一点?这是我的代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Listimizde kaç tane eleman olduğunu bulmak için bunu kullanıyoruz
ListView listView = (ListView) findViewById(R.id.linkList);
String[] links = new String[] { "Facebook", "Ek$iSozluk", "Youtube",
"Twitter", "Hurriyet", "Gmail" };
// ArrayAdapter, bu listviewin nasıl görüneceğini belirtir. ilk argument
// this, yani bu list
// 2. argument list viewin şekli, yani simple dropdown şeklinde olsun,
// 3. argument de links
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, links);
listView.setAdapter(adapter); // start the adapter for the list view
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int pos,
long id) {
// SO listener
Intent myWebLink = new Intent(
android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("http://www.facebook.com"));
switch (pos) {
case 0:
myWebLink.setData(Uri.parse("http://www.facebook.com"));
startActivity(myWebLink);
// go to google
break;
case 1:
myWebLink.setData(Uri.parse("http://www.eksisozluk.com"));
startActivity(myWebLink);
// go to facebook
break;
case 2:
myWebLink.setData(Uri.parse("http://www.youtube.com"));
startActivity(myWebLink);
break;
case 3:
myWebLink.setData(Uri.parse("http://www.twitter.com"));
startActivity(myWebLink);
break;
case 4:
myWebLink.setData(Uri.parse("http://www.hurriyet.com.tr"));
startActivity(myWebLink);
break;
case 5:
myWebLink.setData(Uri.parse("http://www.gmail.com"));
startActivity(myWebLink);
break;
default:
// where ever you want
break;
}
}
});
// OR listener
}
这是我的布局:
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
android:id="@+id/linkList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="@+id/linkList" >
</ListView>
谢谢