2016-11-08 5 views
1

Android 앱을 개발 중입니다. 내 응용 프로그램에서는 대화 상자 같은 활동을 여는 중입니다. 해당 액티비티 배경의 경우 전체 배경에 테두리 반경이있는 이미지를 설정하고 싶습니다. 그래서 나는 이와 같은 백그라운드 XML 자원을 만들었습니다.Android에서 백그라운드 용 이미지로 XML 드로어 블 리소스 사용자 정의

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:drawable="@drawable/match_background_image" /> 
    <item> 
     <shape android:shape="rectangle" android:padding="10dp"> 
      <corners 
       android:bottomRightRadius="5dp" 
       android:bottomLeftRadius="5dp" 
       android:topLeftRadius="5dp" 
       android:topRightRadius="5dp"/> 
     </shape> 
    </item> 

</layer-list> 

이 리소스를 LinearLayout의 배경으로 설정했습니다. 내가 활동을 열 때, 나는 이런 식으로 뭔가를 얻을 :

enter image description here

당신이 코너에서 테두리 반경은 아직 없다. 게다가, 내가하고 싶은 것은 scaleType을 이미지의 cropCenter로 설정하기를 원한다는 것입니다. 그렇다면 XML 리소스만으로도 가능한가?

답변

1

나는 당신에게 더 좋은 방법을 줄 수 있는데, 나는 이것을 대안으로 사용했다. 안드로이드의 cardView를 사용하여 모서리를 둥근 모양으로 만들 수 있습니다.

, 당신의 Gradle을 의존성에 다음

compile 'com.android.support:cardview-v7:25.1.1' 

대화로 열어 다음과 같이 XML을 변경해야 할 활동, 당신이

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/activity_dialog" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    card_view:cardCornerRadius="10dp"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/YOUR_IMAGE"/> 

</android.support.v7.widget.CardView> 

를 사용하는 경우를 cardView 사용을 추가하는 아래와 같이 AppCompatActivity를 확장하는 활동 :

i.e. DialogActivity extends AppCompatActivity 

변경해야하는 활동 다음과 같은 안드로이드 매니페스트에서 활동 테마, 다른

<activity android:name=".DialogActivity" 
      android:theme="@style/Theme.AppCompat.Dialog"></activity> 

<activity android:theme="@android:style/Theme.Dialog" /> 

haaaaa는 어려운 부분은 완료, 이제 당신이해야 할 유일한 것은 전화

startActivity(new Intent(this, DialogActivity.class)); 
입니다