我正在尝试将我的布局设置为 contacts应用程序,这是我的应用程序布局:
我有 2 个 ListView ,一个用于电话,另一个用于电子邮件,我想为每个 ListView 设置一个标题,就像联系人应用程序一样。有人可以指导我如何做吗?
xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, World"
style="?android:attr/listSeparatorTextViewStyle"/>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
>
</ListView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, Universe"
android:layout_above="@+id/listView2"
style="?android:attr/listSeparatorTextViewStyle"/>
<ListView
android:id="@+id/listView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/listView1"
>
</ListView>
</RelativeLayout>
</LinearLayout>
Activity :
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contato_details);
Bundle parametros = getIntent().getExtras();
tele = (ArrayList<ContatosTelefoneModel>) parametros.get("tel");
email = (ArrayList<ContatosEmailModel>) parametros.get("email");
ListView b = (ListView) findViewById(R.id.listView1);
b.setHeaderDividersEnabled(true);
b.setAdapter(new TelefoneListAdapter(this, tele));
ListView e = (ListView) findViewById(R.id.listView2);
e.setHeaderDividersEnabled(true);
e.setAdapter(new EmailListAdapter(this, email));
}
最佳答案
正如您给出的图片,他们使用了 StickyListHeaders
,您可以在此处找到
https://github.com/emilsjolander/StickyListHeaders
你看到的图像顶部是你可以在此处找到的选项卡
https://www.dropbox.com/s/cu6kauu6vhsss45/tabcarousellib.rar
关于java - 带有标题部分的Android自定义 ListView 多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25183262/