Lollipop에서 CardView 사이에 공간이없는 이유는 무엇입니까?
를 사용하려고하는데 CardView
5.0 이하에서 잘 작동하지만 Lollipop에서는 이상하게 보입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<android.support.v7.widget.CardView android:layout_width="match_parent"
android:layout_height="200dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="card1"
android:textAppearance="?android:attr/textAppearanceLarge" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView android:layout_width="match_parent"
android:layout_height="200dp">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="card2"
android:textAppearance="?android:attr/textAppearanceLarge" />
</android.support.v7.widget.CardView>
</LinearLayout>
를 사용할 때 동일한 질문이 나타납니다 RecyclerView
. Lollipop에서 실행되는 경우 추가해야합니까?
이 설정 CardView
:
app:cardUseCompatPadding="true"
문서에서 :
API v21 +에도 패딩을 추가하여 이전 버전과 동일한 측정 값을 갖습니다.
카드보기 내에서 아래 두 태그를 사용하세요.
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
첫 번째 이미지는 카드보기의 예상되는 동작입니다. 카드에 고도가있을 때 그림자는 하단 레이어에 떨어집니다. 사전 롤리팝 장치에서는 패딩을 추가하여 높이를 만듭니다. 따라서 사전 롤리팝 기기는 카드보기 주변에 패딩이 있습니다.
Before L, CardView adds padding to its content and draws shadows to that area. This padding amount is equal to maxCardElevation + (1 - cos45) * cornerRadius on the sides and maxCardElevation * 1.5 + (1 - cos45) * cornerRadius on top and bottom.
You have to add app:cardUseCompatPadding="true"
to your Cardview
. But just adding that may give you an error. To avoid that error, you also have to add xmlns:app="http://schemas.android.com/apk/res-auto"
to your CardView
.
For example,
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:cardUseCompatPadding="true">
// Other views here
</android.support.v7.widget.CardView>
Some would add card_view:cardUseCompatPadding="true"
and xmlns:card_view="http://schemas.android.com/apk/res-auto"
instead of those mentioned above. Both ways are correct.
If you want to know more about app in XML(Android), please go through this answer :
Although previous answers will solve the problem, they didn't explain what each attribute does. So to be more helpful to answer seekers,
cardPreventCornerOverlap
속성은 카드 콘텐츠와 둥근 모서리 사이의 교차를 방지하기 위해 v20 이전 버전의 CardView에 패딩을 추가합니다.
cardUseCompatPadding
속성은 API v21 +에 패딩을 추가하여 이전 버전과 동일한 측정 값을 갖습니다.
참고 URL : https://stackoverflow.com/questions/27035647/why-there-is-no-space-between-cardviews-on-lollipop
'program tip' 카테고리의 다른 글
iOS : 숫자에서 적절한 월 이름을 얻는 방법은 무엇입니까? (0) | 2020.10.11 |
---|---|
ResourceConfig 인스턴스에 루트 리소스 클래스가 없습니다. (0) | 2020.10.11 |
숨겨진 파일이없는 cp -r (0) | 2020.10.10 |
adb shell을 사용하여 안드로이드 폰의 모든 파일을 나열하는 방법은 무엇입니까? (0) | 2020.10.10 |
python3을 사용하여 jupyter 노트북의 상대 가져 오기와 함께 다른 디렉토리에있는 모듈에서 로컬 함수 가져 오기 (0) | 2020.10.10 |