我有一個線性佈局,顯示在屏幕上沒有列表'滾動列表的完整列表。我使用列表視圖,但不能顯示所有項目同時沒有滾動。現在我想添加粘性標題視圖到線性佈局這個列表。我應該選擇什麼方法?我可以將粘性標題視圖添加到線性佈局嗎?
l1= (LinearLayout) findViewById(R.id.list1);
l2= (LinearLayout) findViewById(R.id.list2);
retrofit=new Retrofit.Builder().baseUrl("http://taskism.com").addConverterFactory(GsonConverterFactory.create()).build();
Login_api newcall=retrofit.create(Login_api.class);
Call<inst_model> mycall=newcall.gettasksteplist("tasksteplist","223","62");
mycall.enqueue(new Callback<inst_model>() {
@Override
public void onResponse(Response<inst_model> response, Retrofit retrofit) {
progressDialog.setIndeterminate(false);
progressDialog.dismiss();
tasksteps=response.body().getTasksteps();
adapter1=new adapter1(instructions.this,R.layout.adapter1,tasksteps);
for (int i = 0; i < adapter1.getCount(); i++) {
View view = adapter1.getView(i, null, l1);
l1.addView(view);
}
}
@Override
public void onFailure(Throwable t) {
}
});
Login_api allcomnt=retrofit.create(Login_api.class);
Call<Commentall> allcomm=allcomnt.commentall("commentall", "222", "14");
allcomm.enqueue(new Callback<Commentall>() {
@Override
public void onResponse(Response<Commentall> response, Retrofit retrofit) {
List<Comment> allcom=response.body().getComments();
adapter2 =new adapter2(instructions.this,R.layout.adapter2,allcom);
for (int i = 0; i < adapter2.getCount(); i++) {
View view = adapter2.getView(i, null, l2);
l2.addView(view);
}
}
@Override
public void onFailure(Throwable t) {
}
});
}
和佈局如下
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:id="@+id/instname"
android:textColor="@android:color/black"
android:layout_marginBottom="10dp"
android:text="Gairy J"
android:gravity="center_horizontal"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/steps"
android:text="Steps"
android:src="@drawable/icon_cancel"
android:textColor="@android:color/holo_green_light"
android:gravity="center_horizontal"
android:layout_below="@id/instname"/>
<LinearLayout
android:layout_below="@id/steps"
android:layout_width="match_parent"
android:id="@+id/list1"
android:orientation="vertical"
android:dividerHeight="1dp"
android:layout_height="wrap_content">
</LinearLayout>
<TextView
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Comments"
android:id="@+id/comment"
android:gravity="center_horizontal"
android:textColor="@android:color/holo_green_light"
android:layout_below="@id/list1"
android:layout_marginBottom="10dp"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:id="@+id/list2"
android:layout_marginLeft="10dp"
android:dividerHeight="1dp"
android:layout_below="@id/comment"
android:layout_height="wrap_content">
</LinearLayout>
</RelativeLayout>
</ScrollView>
感謝,但我的問題解決了https://github.com/emilsjolander/StickyScrollViewItems –