2011-12-16 3 views
0

내 이미지가 내 이미지보기 범위 내에 있지 않은 이유를 파악하는 데 문제가 있습니다. 대신, 그것은 왼쪽으로 떠돌아 다니고 숨겨져 있습니다. 이것은 그래픽 인터페이스가 보여주지 않기 때문입니까?이미지가 이미지보기 범위를 벗어납니다.

는 편집 :

enter image description here

:

나는 (내가 이미지가 빨간색 상자에 표시 할) 더 명확하게 나는 데 문제를 보여 원래의 코드를 편집하고 사진을 추가
<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    android:id="@+id/top_container" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"  
    android:gravity="center" 
    > 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     > 
     <View 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="195" 
      android:background="#00FF00"/> 
     <ImageView 
      android:id="@+id/img" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:background="#ff0000" 
      android:src="@drawable/img" /> 

     <View 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:background="#0000FF" 
     /> 
    </LinearLayout> 
</LinearLayout> 

답변

0

좋습니다. 작동 중입니다. "block_container"의 height 속성은 무작위로 200dp로 설정되어 있으며 높이를 원하는대로 변경하거나 "wrap_content"로 설정할 수 있습니다. 나는 이것을 에뮬레이터와 장치에서 테스트했다.

또한 세 블록 모두 동일한 간격으로 배치되기를 원한다고 가정합니다. 부모 "block_container"의 weight_sum 값이 9인지 확인하십시오. 글쎄요, 아이들은 각각 3의 무게를 가지고 있기 때문에 같은 폭입니다 (3 블록 * 3 무게 = 9 무게 합계).

예를 들어 체중을 너비로 직접 사용하려고 한 것처럼 보였습니다. 569의 무게. 그냥 무게 = 너비를 직접 기억하십시오.

편집 : 누락 된 ID가 나는 문제를 조금 업데이트 전망

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/top_container" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    <LinearLayout 
     android:id="@+id/block_container" 
     android:layout_width="fill_parent" 
     android:layout_height="200dp" 
     android:orientation="horizontal" 
     android:weightSum="9" 
     > 
     <View 
      android:id="@+id/left_block" 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="3" 
      android:background="#00FF00"/> 
     <ImageView 
      android:id="@+id/img" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="3" 
      android:background="#ff0000" 
      android:src="@drawable/logo" /> 

     <View 
      android:id="@+id/right_block" 
      android:layout_height="fill_parent" 
      android:layout_width="0dp" 
      android:layout_weight="3" 
      android:background="#0000FF" 
     /> 
    </LinearLayout> 
</LinearLayout> 
0

android:layout_height을 0dp로 설정하는 이유는 무엇입니까? 내가 이것을 fill_parent과 같은 것으로 바꾸지 않으면 나는 그것을 표시 할 수 없다.

어느 쪽이든, layout_weight 부모의 경우 LinearLayout입니다. ImageView에 대해 큰 layout_weight을 지정하면 표시됩니다.

<ImageView 
     android:id="@+id/my_img" 
     android:gravity="center" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="279" 
     android:src="@drawable/my_img" /> 

이것은 나를 위해 일했습니다 ..하지만 수학은 옳지 않을 수도 있습니다.

+0

의 일부에서 속성을 추가했다. 어쩌면 내가 뭔가를 이해하지 못하겠습니까?나는 체중을 늘릴 필요가있다. 이미지가 경계에 있어야하지 않습니까? – prostock

+0

시도해 보셨습니까? 문제를 복제하고 ImageView의 무게를 늘려서 문제를 해결했습니다. – styler1972

0

난 당신이 무엇을 게시와 함께 문제로 시작 위치를 모르는, 더욱 디버깅하기 전에 몇 가지 간단한 관찰 :

  • 귀하의 레이아웃은 모든 식별자 (예 : 안드로이드 필요 : ID를 = "@ + ID/another_layout ")
  • 당신은 0dp의 두 번째 선형 레이아웃에 폭이
  • 첫 번째 선형 레이아웃이 이전과 결합 공 (DP)의 높이, 나는 모든
  • 마지막 내부 선형에서 렌더링 놀랐어요 레이아웃의 너비는 0dp입니다.

달성하려는 목표는 무엇입니까? 내게는 이해하기 쉽게 몇 가지 요소를 제거하지 않는 한 많은 레이아웃이있는 것 같습니다. 당신이하려고하는 것에 대한 단순한 이미지를 게시 할 수 있으며 마크 업을 수정하는 데 도움을 줄 수 있습니까?

+0

님이 그림을 추가하고 코드를 편집하여 더 나은 아이디어를 얻을 수있었습니다. 나는 0dp를 추가했다. 왜냐하면 나는 너비와 높이를 구체화하기 위해 체중을 사용하려고 노력하고있다. – prostock

+0

Graham Smith와 동의한다. 당신이하려고하는 것을 성취하기위한 더 좋은 방법 인 것 같다. – styler1972

관련 문제