2016-08-29 3 views
1

스플래시 화면이있는 앱이 있으며 스플래시 화면이 작은 기기에서는 좋지만 모양이 큰 태블릿 (에뮬레이터)에서는 엉망으로 보입니다. 그래서 배경을 wrap_content으로 변경했습니다. 하지만 화면의 측면에 맞춰 보입니다. 어떤 사람이 배경 이미지를 중앙에 배치 할 수있는 방법을 말해 줄 수 있습니까? 여기 내 splash.xml-는Android : 센터 스플래시 화면 이미지

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="@drawable/splash"> 
</LinearLayout> 
+1

가능한 [Android : Center and image] (http://stackoverflow.com/questions/6101874/android-center-an-image) – Zoe

답변

1

당신은 실제로 대신 FrameLayout 더 가볍고을 사용, 여기에 어느 LinearLayoutRelativeLayout 필요하지 않습니다 수 있습니다.

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:src="@drawable/splash" 
     android:layout_gravity="center" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 

</FrameLayout> 
+0

고맙습니다! –

0

시도하십시오

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/splash"> 
</LinearLayout> 
+0

의 가능한 복제본 무엇입니까? 왜 변경되지 않은 코드를 게시 했습니까? – Zoe

+0

@ Polarbear0106 plz 코드를 확인하십시오. – Halumz

+0

아니야 .... – Zoe

0

을 다음 당신은 아래의 코드를 시도, 상대 레이아웃을 사용할 수 있습니다 .. 코드

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerInParent="true" 
     android:src="@mipmap/ic_launcher" /> 
</RelativeLayout> 
0

약간의 변화 등이다 가장 적합한 두 번째 요소를 추가해야합니다.

<?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:background="#2A7800"<---- optional background color to fit the image. to make it blend in 
    android:orientation="vertical"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="center_horizontal"<--- centers 
     android:adjustViewBounds="true" 
     android:scaleType="fitXY"<--- makes sure the image fits into the layout my matching the screen size. 

     android:src="@drawable/splash" /> 
</LinearLayout> 

ImageView를 추가하는 것은 android : background를 사용하고 이미지를 설정하는 것보다 더 나은 성능을 발휘하는 가장 좋은 방법입니다. 나는 이것을 ScrollView에서 발견했으며 마스터 부모는 android : 배경을 이미지로 설정했다. 그것은 ScrollView를 극단적으로 느리게 만들었습니다.

또한이 방법으로 특정 레이아웃을 사용할 필요가 없습니다. RelativeLayout, FrameLayout, LinearLayout을 사용할 수 있습니다. 예외는 ListView를,의 GridView는

0

내 활동에 대한 배경 이미지를 사용하고 있습니다. 먼저 styles.xml의 테마를 만들 :

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> 
    <item name="android:windowBackground">@drawable/background_splash</item> 
</style> 

그런

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@color/colorWhite"/> 
     <item> 
      <bitmap 
       android:gravity="center" 
       android:src="@drawable/logo_splash"/> 
     </item> 
</layer-list> 

그런 다음 당신의 AndroidManifest.xml에서이 테마를 사용하는 활동을 설정 이름 background_splash.xml으로 새로운 당김을 만듭니다

<activity android:name="SplashActivity" android:theme="@style/SplashTheme" > 

이것은 나를 위해 일했습니다.