2012-05-15 4 views
1

나는 다음과 같은 간단한 레이아웃ScrollView에서 배경색을 어떻게 설정할 수 있습니까?

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <RelativeLayout 
     android:id="@+id/answerMainFrame" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/background" 
     android:isScrollContainer="true" 
     android:onClick="toAnswer" > 

     <ImageView 
      android:id="@+id/answer_img" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true" 
      android:contentDescription="@string/question_img_cd" /> 

     <TextView 
      android:id="@+id/answer" 
      style="@style/Question" 
      android:layout_below="@id/answer_img" /> 
    </RelativeLayout> 

</ScrollView> 

하지만 때로는 이미지 뷰와 텍스트 뷰의 크기에 따라, 그것은 화면의 높이를 기입하지 않습니다에게 있습니다. 괜찮아. 화면의 나머지 부분을 검정색 대신 흰색으로 바꾸기 만하면됩니다.

흰 바탕에 흰색으로 설정 한 android:background="@color/background"을 시도했지만 동일한 결과를 얻었습니다.

Relativelayout에 android:layout_height="wrap_content" 설정을 시도했지만 경고가 표시됩니다.

어떻게해야합니까?

감사합니다.

답변

3

높이를 match_parent으로 변경하고 흰색을 배경으로 설정하십시오. 코드에 따라 다음과 같이 표시됩니다.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" 
        android:layout_height="match_parent" 
        android:background="@color/background"> 
... 

참고. RelativeLayout에 대한 경고는 쉽게 설명 할 수 있습니다. 높이를 wrap_content으로 설정하면 내부에있는 요소에 부모가 바닥에 부착하거나 가운데에 붙이는 등의 작업을 수행 할 수 있도록 치수가 고정되어 있어야하기 때문에 불가능합니다.

나는 또한 이것에 대해 처음에는 약간의 혼란을 겪었다.

+0

정말 고마워요 @thisMayhem 좋아해요. 그것은 매력처럼 작용했습니다. 그것은 분명한 대답으로 보였다. 나는 이미 그걸 시도했다고 생각 했어. – eskalera

+0

@eskalera 붙어있을 때 눈이 더 뜨거워지면 항상 도움이됩니다. 다행이었습니다. –

1

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#ffffff > 

<RelativeLayout 
    android:id="@+id/answerMainFrame" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@color/background" 
    android:isScrollContainer="true" 
    android:onClick="toAnswer" > 

    <ImageView 
     android:id="@+id/answer_img" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:contentDescription="@string/question_img_cd" /> 

    <TextView 
     android:id="@+id/answer" 
     style="@style/Question" 
     android:layout_below="@id/answer_img" /> 
</RelativeLayout> </ScrollView> 
+0

감사합니다. Nikhil-lamba, 맞습니다. – eskalera

+0

@eskalera : 우호 문제를 해결하는 즐거움 :) –

관련 문제