Recyclerview未全屏顯示。以下是佈局文件和我寫的代碼。執行後,內容顯示如下圖所示。高度只是突出部分。我希望內容是全屏。 我剩下的內容在這個可滾動的高亮區域內。我希望內容以全屏顯示。任何幫助都會有所幫助。Recyclerview未全屏顯示
版式文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/activity_search"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:clickable="true">
<TextView
android:id="@+id/title"
android:textSize="16dp"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/genre"
android:layout_below="@id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/year"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
代碼:
進口android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import java.util.List;
公共類setSearchData延伸RecyclerView.Adapter {
private List<SearchDisplayContents> moviesList; public class MyViewHolder extends RecyclerView.ViewHolder { public TextView title, year, genre; public MyViewHolder(View view) { super(view); title = (TextView) view.findViewById(R.id.title); genre = (TextView) view.findViewById(R.id.genre); year = (TextView) view.findViewById(R.id.year); } } @Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.activity_searchresults, parent, false); return new MyViewHolder(itemView); } @Override public void onBindViewHolder(MyViewHolder holder, int position) { SearchDisplayContents movie = moviesList.get(position); holder.title.setText(movie.getTitle()); holder.genre.setText(movie.getGenre()); holder.year.setText(movie.getYear()); } @Override public int getItemCount() { return moviesList.size(); }
}
調用功能的代碼:
列表movieList =新的ArrayList <>(); RecyclerView recyclerView =(RecyclerView)findViewById(R.id.recycler_view);
setSearchData mAdapter = new setSearchData(movieList); RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); recyclerView.setLayoutManager(mLayoutManager); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setAdapter(mAdapter); SearchDisplayContents movie = new SearchDisplayContents("Mad Max: Fury Road", "Action & Adventure", "2015"); movieList.add(movie); movie = new SearchDisplayContents("Inside Out", "Animation, Kids & Family", "2015"); movieList.add(movie); mAdapter.notifyDataSetChanged();
請出示整個佈局文件 – xklakoux
佈局文件已完成。請檢查 – Nikhil
請告訴我們:activity_searchresults.xml – xklakoux