不是从ListActivity扩展,而是从一个简单的Activity扩展你的类,并在该活动中放置一个ListView,你可以给边距和填充ListView。只需使用已经使用ListView创建的同一个适配器即可。这是如何。 这是您的活动的布局文件,称它为activity_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:marginTop="20sp"
android:marginBottom="10sp"
android:divider="@android:color/transparent"
android:id="@+id/listview"
android:padding="5sp"
android:dividerHeight="5.0sp"
></ListView>
</RelativeLayout>
现在在Java中创建一个活动。
public class MyListActivity extends Activity {
private ListView listView;
private MyAdapter myAdapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
this.listView = (ListView) findViewById(R.id.listview);
this.myAdapter = new MyAdapter(getApplicationContext());
//add whatever you want to add to your adapter
listView.setAdapter(myAdapter);
}
}
我希望这可以解决您的问题!
你希望整个事物的margin_top为100dp?只需将其添加到容器视图组。 – m02ph3u5
@ m02ph3u5虽然这里没有容器。这两种布局都在单独的文件中,并且不会出现在任何地方的容器中。我误解了吗? –
不知道如果你可以用'ListActivity'来做到这一点,但尝试获取列表(它的id是'list')并以编程方式添加一个边距。请参阅http://developer.android.com/reference/android/app/ListActivity.html – m02ph3u5