match_parent width가 RecyclerView에서 작동하지 않습니다.
내 RecyclerView 및 항목의 부모 너비는 match_parent width이지만 결과는 다음과 같습니다.
<view
class="android.support.v7.widget.RecyclerView"
android:layout_width="match_parent"
항목:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/ll_itm"
android:orientation="horizontal"
android:layout_width="match_parent"
전체:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/ll_itm"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:gravity="right"
>
<Button
android:layout_width="0dp"
android:layout_weight="15"
android:layout_height="fill_parent"
android:text="ملاحظات"
android:id="@+id/button" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20"
android:gravity="center"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
fab:fab_plusIconColor="#ff56ff83"
fab:fab_colorNormal="@color/d_red"
fab:fab_colorPressed="#ff5c86ff"
fab:fab_size="mini"
fab:fab_icon="@drawable/ic_remove_white"
android:id="@+id/fab_rmv" />
<esfandune.ir.elmikarbordiardakan.other.CustomTxtView
android:layout_weight="25"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="0"
android:gravity="right|center_vertical"
android:id="@+id/txt_takhir_itm" />
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
fab:fab_plusIconColor="@color/colorprimarylight"
fab:fab_colorNormal="@color/colorprimarydark"
fab:fab_colorPressed="@color/colorprimary"
fab:fab_size="mini"
fab:fab_icon="@drawable/ic_add_white"
android:id="@+id/fab_add" />
</LinearLayout>
</LinearLayout>
<Spinner
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="10"
android:id="@+id/sp_nomre_itm"
android:entries="@array/degrees"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="10"
android:gravity="center"
>
<!--LinearLayout baraye ine ke nameshod fab ro weight behosh dad-->
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
fab:fab_plusIconColor="#ff56ff83"
fab:fab_colorNormal="@color/d_green"
fab:fab_colorPressed="@color/d_orange"
fab:fab_size="normal"
fab:fab_icon="@drawable/ic_done_white"
android:id="@+id/fab_hazr" />
</LinearLayout>
<esfandune.ir.elmikarbordiardakan.other.CustomTxtView
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="100"
android:gravity="right|center_vertical"
android:id="@+id/txt_ghybtNumber_itm" />
<esfandune.ir.elmikarbordiardakan.other.CustomTxtView
android:layout_weight="30"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="عباسعلی ملاحسینی اردکانی"
android:gravity="right|center_vertical"
android:id="@+id/txt_title_itm"
android:layout_marginRight="10dp"
/>
<view
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="10"
class="de.hdodenhof.circleimageview.CircleImageView"
android:id="@+id/view"
android:src="@drawable/mmrdf"
/>
</LinearLayout>
항목을 부풀리는 어댑터에서onCreateViewHolder, 는 의 두번째 파라미터입니다.inflate불러null?.
그렇다면 다음으로 바꿉니다.parent의 첫번째 파라미터입니다.onCreateViewHolder함수 서명.
View rootView = LayoutInflater.from(context).inflate(R.layout.itemLayout, parent, false);
두 번째 파라미터가 필요한 경우null그런 다음 팽창에 대한 뷰 참조를 얻으면 다음을 수행합니다.
View rootView = LayoutInflater.from(context).inflate(R.layout.itemLayout, null, false);
RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
rootView.setLayoutParams(lp);
return new RecyclerViewHolder(rootView);
CreateView의 Inside보기를 부풀리는 어댑터의 홀더(...) 메서드입니다.ViewGroup을 상위 그룹으로 정의해야 합니다.onCreateView의 첫 번째 매개 변수에서 얻을 수 있습니다.홀더(...) 메서드입니다.
ViewGroup을 통과하는 두 번째 매개 변수의 아래 줄을 참조하십시오.이렇게 하면 보기가 해당 상위 보기와 자동으로 일치합니다.
rowView=inflater.inflate(R.layout.home_custom_list, parent,false);
///전체 코드는 아래와 같습니다.
public View onCreateViewHolder(ViewGroup parent, int position) {
// TODO Auto-generated method stub
View rowView;
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView=inflater.inflate(R.layout.home_custom_list, parent,false);
나는 a를 사용하고 있었습니다.FrameLayout와 함께MATCH_PARENT폭에 대하여 그리고 a와 같은 행동을 보고 있었습니다.RecyclerView+LinearLayoutManager. 다음과 같은 작업을 수행하기 전까지 위의 변경 사항 중 어떤 것도 효과가 없었습니다.onCreateViewHolder콜백:
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// create a new view
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.note_layout, parent, false);
v.setLayoutParams(new RecyclerView.LayoutParams(
((RecyclerView) parent).getLayoutManager().getWidth(),
context.getResources()
.getDimensionPixelSize(R.dimen.note_item_height)));
return new ViewHolder(v);
}
리사이클러뷰 구현에 버그가 있는 것 같습니다.
저는 이렇게 고쳤습니다.루트 액티비티 레이아웃으로 ConstraintLayout을 사용하기 때문에 액티비티 레이아웃 파일에 문제가 있습니다.당신도 그럴 수 있습니다
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolBar"
layout="@layout/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/accent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolBar" />
</android.support.constraint.ConstraintLayout>
저는 이게 통했어요.
이것을 대신합니다.
View view = View.inflate(parent.getContext(), R.layout.row_timeline, null);
return new TimeLineViewHolder(view, viewType);
이로써
View rootView = LayoutInflater.from(context).inflate(R.layout.row_timeline, null, false);
RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
rootView.setLayoutParams(lp);
return new TimeLineViewHolder(rootView, viewType);
어댑터의 항목에 대한 레이아웃 파라미터를 설정할 때 이를 시도해 보십시오.
View viewHolder= LayoutInflater.from(parent.getContext())
.inflate(R.layout.item, parent, false);
viewHolder.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
ViewOffersHolder viewOffersHolder = new ViewOffersHolder(viewHolder);
return viewOffersHolder;
저의 경우, 문제는.RecyclerViewXML 선언,layout_widthmatch_constraints를 의미하는 0dp로 변경했을 때match_parent, 모든 것을 채우기 시작했습니다.RecyclerView너비:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp" <-- changed this to "match_parent"
android:layout_height="0dp"
android:layout_marginBottom="45dp"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_default="wrap"
app:layout_constraintHeight_max="360dp"
app:layout_constraintHeight_min="60dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/header"/>
단순히 루트에 높이와 너비가 0인 더미 뷰를 추가하는 것이 효과적이었습니다.
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".screen.gallery.GalleryFragment">
<!----DUMMY VIEW----->
<View
android:layout_width="match_parent"
android:layout_height="0dp"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/navigationList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
/>
리사이클러 뷰에 사용되는 복합 뷰에 선형 레이아웃과 제약 조건 레이아웃을 사용할 때도 동일한 문제에 직면했지만 해당 복합 뷰에 대해 상대 레이아웃으로 변경할 때는 작동했습니다.
이 문제를 해결했습니다.
myInflatedRowLayout.getLayoutParams().width = vg.getWidth();
그것은 그것을 대체하고 있습니다.MATCH_PARENT실제 너비로RecyclerView.
저는 한동안 이 문제에 갇혀 있었는데, 저에게 효과가 있었던 해결책은 match_parent와 함께 2개의 뷰를 배치하고, 하나는 내부에 배치하는 것이었습니다.
목록 항목의 레이아웃에서 이 작업을 수행한 경우:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#F00"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent">
</RelativeLayout>
다른 사람들이 언급한 것처럼 상대적인 레이아웃이고, 저는 상위 보기를 통과하고 있지만 인플레이터에서 거짓이지만, 그것은 전혀 나타나지 않을 것입니다(확인할 빨간색 배경).
하지만 내가 이렇게 했을 때는
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:background="#0F0"
android:layout_height="match_parent"/>
</RelativeLayout>
녹색 배치가 나타나 전체 공간을 차지했습니다.
그래서 match_parent가 있는 메인 뷰 안에 어린이 뷰가 있는 것만으로도 문제가 해결됩니다. 이유를 모르겠습니다.
전체 코드를 볼 수는 없지만 선형 배치 내부의 일부 보기는 '라고 추측할 수 있습니다.wrap_content'. '을(를) 사용하여 하나 또는 일부를 전체 너비로 확장해야 합니다.android:layout_weight="1"'
update: 중복된 것이 많습니다.layout_weight것으로 요. 다 만들어요.wrap_content' 그리고 그들 중 한 명만이 추가됩니다.layout_weight=1- 전관예절을 위하여텍스트 보기.이렇게 하면 빈 공간을 모두 차지하게 됩니다.
언급URL : https://stackoverflow.com/questions/30691150/match-parent-width-does-not-work-in-recyclerview
'programing' 카테고리의 다른 글
| jquery - .done (),의 사용 .done () .다음으로 () 및 .ajax 요청을 지정된 순서로 수행하기 위한 () 시 (0) | 2023.10.31 |
|---|---|
| "JDBC 드라이버 인스턴스화 할 수 없음" 플라이웨이 명령줄 오류 수정 방법? (0) | 2023.10.31 |
| Http에 매개변수를 추가하는 방법NameValuePair를 사용하여 POST를 사용한 URL 연결 (0) | 2023.10.31 |
| WordPress 3.5 이후에도 Media_upload_tabs 필터를 사용하여 미디어 관리자에 탭을 추가해야 합니까? (0) | 2023.10.31 |
| jQuery를 사용하여 문자열에서 마지막 문자를 삭제하는 방법? (0) | 2023.10.31 |