2011-04-29 4 views
10

다음과 같은 문제가 있습니다.LinearLayout의 배율 배경 이미지

나는 LinearLayout에 ScrollView를 가지고 있는데, ScrollView는 사용자 정의보기이다. 이제 LinearLayout 배경에 이미지를 놓고 원래 크기로 이미지를 유지하려고합니다. 그러나 LinearLayout의 배경 속성을 설정하면 전체 화면에 맞게 늘어납니다. 이미지를 원래 크기로 유지하려면 어떻게해야합니까?

내 XML :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/root" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/some_drawable"> 
    <ScrollView 
    android:id="@+id/scrollview" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:fillViewport="true"> 
    <some.custom.layout 
     android:id="@+id/mainLayout" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     /> 
    </ScrollView> 
</LinearLayout> 

답변

20

내부에 ImageView 및 LinearLayout이있는 FrameLayout을 사용해보십시오. 예를 들어, 이미지의 알파를 변경하고 FrameLayout에서 포어 그라운드로 이동하면 LinearLayout이 백그라운드로 유지됩니다. 희망이 도움이!

에고의 답변
+0

이것은 나를 위해 일했습니다. 덕분에 많이! – Joris

+1

잘 작동하지만 생각보다 우아한 해결책은 http://stackoverflow.com/questions/2781593/background-image-placement에서 찾을 수 있습니다. – iganev

0

당신은 InsetDrawable 한 번 봐 걸릴 수 있습니다. 어느 쪽이든 아니면 그것은 배경 요소가 필요로하는 능력을 가지지 않기 때문에 당신이 바라는 방식을 그리기 위해 당신의 레이아웃을 서브 클래스 할 것을 요구할 것입니다.

0

ColdForged의 제안에 따라 LinearLayout에서 RelativeLayout으로 이동하고 ImageView을 사용하여 배경을 배경으로 변경하는 대신 이미지를 표시 할 수 있습니다. RelativeLayout의보기는 LinearLayout과 달리 간섭 할 수 있습니다.

+0

나는이 시도했지만, 어떻게 있도록 이미지가 배경 인 이미지보기 위에있는 ScrollView의 내용을 그릴 수 있습니까? – Joris

+1

아마 scrollview 배경에 알파를 설정하여 – ernazm

21

코드 예제 :

<FrameLayout 
    android:id="@+id/FrameLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    > 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:src="@drawable/background" 
     /> 

    <LinearLayout 
     android:id="@+id/LinearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     > 

    </LinearLayout> 

</FrameLayout>