주변을 수색했지만 적절한 방법을 찾지 못했습니다. 내 뷰에 다음과 같은 그림자 효과를 적용하고 싶습니다.
솔직히이 두 번째는 그림자 효과를 적용한 것인지 모르겠습니다. 어떤 아이디어?
답변
이 질문에 이미 대답했습니다 알고하지만 난 당신이 내가 발견 알고 싶어요 drawable
에 Android Studio
그건 당신이 질문에 가지고있는 사진과 매우 유사합니다 : 이것 좀 봐 :
android:background="@drawable/abc_menu_dropdown_panel_holo_light"
다음과 같이 보입니다.
도움이 되길 바랍니다
편집하다
위의 옵션은의 이전 버전 용 Android Studio
이므로 찾지 못할 수 있습니다. 최신 버전 :
android:background="@android:drawable/dialog_holo_light_frame"
또한 나만의 모양을 만들고 싶다면 같은 그리기 소프트웨어를 사용하여 그리는 것이 좋습니다 Photoshop
.
로 저장하는 것을 잊지 마세요 .9.png
파일 (예 : my_background.9.png
)
문서 읽기 : Draw 9-patch
편집 2
더 좋고 덜 열심히 일하는 솔루션은 보기가 테두리와 겹치지 않도록 CardView
및 설정 app:cardPreventCornerOverlap="false"
을 사용하는 것입니다 .
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="2dp"
app:cardElevation="2dp"
app:cardPreventCornerOverlap="false"
app:contentPadding="0dp">
<!-- your layout stuff here -->
</android.support.v7.widget.CardView>
또한 최신 버전을 포함 시켰해야합니다 build.gradle
, 전류를
compile 'com.android.support:cardview-v7:26.0.0'
답변
Android Studio 0.8.6을 사용하고 있는데 다음을 찾을 수 없습니다.
android:background="@drawable/abc_menu_dropdown_panel_holo_light"
그래서 대신 이것을 찾았습니다.
android:background="@android:drawable/dialog_holo_light_frame"
그리고 다음과 같이 보입니다 :
답변
배경을 넣는 것은 @android:drawable/dialog_holo_light_frame
그림자를 제공하지만 배경색이나 테두리 스타일을 변경할 수 없으므로 레이어 목록을 통해 배경을 넣을 수 있지만 그림자를 활용하는 것이 좋습니다.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--the shadow comes from here-->
<item
android:bottom="0dp"
android:drawable="@android:drawable/dialog_holo_light_frame"
android:left="0dp"
android:right="0dp"
android:top="0dp">
</item>
<item
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp">
<!--whatever you want in the background, here i preferred solid white -->
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
</shape>
</item>
</layer-list>
아래의 drawable 폴더에 저장하십시오. shadow.xml
뷰에 할당하려면 xml 레이아웃 파일에서 배경을 설정하십시오.
android:background="@drawable/shadow"
답변
res / drawable 폴더에 다음 코드를 사용하여 card_background.xml을 만듭니다.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#BDBDBD"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
그런 다음 카드 레이아웃을 원하는 요소에 다음 코드를 추가하십시오.
android:background="@drawable/card_background"
다음 줄은 카드의 그림자 색상을 정의합니다.
<solid android:color="#BDBDBD"/>
답변
CardView 는 Android 5 이상에서 진정한 그림자를 제공 하며 지원 라이브러리가 있습니다. 보기를 감싸면 끝입니다.
<android.support.v7.widget.CardView>
<MyLayout>
</android.support.v7.widget.CardView>
다음 종속성이 필요합니다.
dependencies {
...
compile 'com.android.support:cardview-v7:21.0.+'
}
답변
고도 속성을 사용하여 그림자 효과를 얻으십시오.
<View ...
android:elevation="2dp"/>
이것은 v21 이후에만 사용됩니다. http://developer.android.com/training/material/shadows-clipping.html 링크를 확인 하십시오.
답변
이것은 늦었을지 모르지만 여전히 이것에 대한 답을 찾고있는 사람들을 위해 git hub에서 프로젝트를 찾았으며 이것이 실제로 내 요구에 맞는 유일한 프로젝트입니다. android-materialshadowninepatch
build.gradle 종속성에이 줄을 추가하면됩니다.
compile 'com.h6ah4i.android.materialshadowninepatch:materialshadowninepatch:0.6.3'
건배. 제작자에게 좋아요! 행복한 코딩