2012-02-29 3 views
0

왼쪽에서 긴 이미지 (좁은 이미지)와 오른쪽 이미지에서 긴 이미지를 표시하는 HorizontalScrollView가 구현 된 LinearLayout을 구현했습니다.안드로이드 : HorizontalScrollView 및 이미지 래핑

문제는 내가 HorizontalScrollView를 제대로 처리하지 못했다는 것입니다. 그것은 이미지의 왼쪽 부분을 보여주지 않습니다 (나는 그 방향으로 스크롤 할 수 없습니다). 그리고 다른면의 이미지 테두리를 훨씬 넘어서 스크롤 할 수 있습니다 ...

스크린 샷은 왼쪽 끝으로 스크롤됩니다. 가능한 한 (이미지의 왼쪽 부분이 잘 렸음을 유의하십시오.) 가능한 한 맨 오른쪽의 모든 공백과 소스 이미지는 모두 http://folk.ntnu.no/anderfo/pics/temp/android/ (총 4 개의 이미지)에 제공됩니다.
은 (내가 여기를 보여주고 싶었다, 그러나 유래에 따라 내가 미안 이미지를 ... 게시 충분히 높은 "명성"을 필요가 없습니다.) 나는 이미지와 대한 포장의 다른 유형을 시도

HorizontalScrollView,하지만 문제는 항상 동일합니다.

또한 왼쪽 이미지에 문제가 있습니다. 줄 바꿈이 작동하지 않으므로 양쪽에 공백이 있습니다.

이 설명하기 어려운, 그래서 대신 당신에게 문제를 제시 몇 가지 예제 코드 줄 것이다 :

XML 파일을 (나는 그것의 많은 버전을했지만 항상 같은 문제를 가진 한) :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:adjustViewBounds="true" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:id="@+id/leftContainer" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:adjustViewBounds="true" 
     android:orientation="horizontal" > 
     <ImageView 
      android:id="@+id/ivExampleBar" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:paddingLeft="0dp" 
      android:paddingRight="0dp" 
      android:contentDescription="Bar on the left side" 
      android:src="@drawable/examplebar" /> 
    </LinearLayout> 

    <HorizontalScrollView 
     android:id="@+id/hscroll" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_gravity="left" 
     android:scrollbarFadeDuration="0"> 

     <LinearLayout 
       android:id="@+id/container" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:layout_gravity="center_horizontal" 
       android:orientation="horizontal" > 

       <ImageView 
       android:id="@+id/ivExampleImg" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:contentDescription="Big scrollable image" 
       android:src="@drawable/exampleimg" 
      /> 
     </LinearLayout> 
    </HorizontalScrollView> 

</LinearLayout> 

자바 파일 (또한 이미지의 왼쪽 부분을 보여주기 위해 내가 ScrollTo을 시도했다, 그러나 ... 단지 특정 해상도/휴대 전화에서 작동) :

import android.app.Activity; 
    import android.os.Bundle; 
    import android.view.Window; 
    import android.view.WindowManager; 
    import android.widget.LinearLayout; 

    public class TestActivity extends Activity { 

     //private LinearLayout scrollContainer; 

     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      // FULL SCREEN 
      requestWindowFeature(Window.FEATURE_NO_TITLE); 
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
      this.setContentView(R.layout.testlayout); 

      //scrollContainer = (LinearLayout) findViewById(R.id.container); 
      //scrollContainer.scrollTo(-195, 0); 


     } 

     @Override 
     protected void onPause(){ 
      super.onPause(); 
      finish(); 
     } 
    } 

당신이 있습니까 이러한 문제에 대한 도움이 필요하십니까?

  • 이 가능 왼쪽 이미지 주위의 공백을 피하기 이미지
  • 의 경계에 모든 방법을 스크롤 할 수 있도록 주위에는 공백이 없기 때문에 HorizontalScrollView 내 이미지를 포장 할

건배,
앤더스

여전히 공백 문제와 ChristopheCVB (도움 후

업데이트 된 XML 파일 두 사진) :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:adjustViewBounds="true" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/ivExampleBar" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:paddingLeft="0dp" 
     android:paddingRight="0dp" 
     android:layout_alignParentLeft="true" 
     android:contentDescription="Bar on the left side" 
     android:src="@drawable/examplebar" /> 

    <HorizontalScrollView 
     android:id="@+id/hscroll" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_gravity="left" 
     android:layout_toRightOf="@+id/ivExampleBar" 
     android:scrollbarFadeDuration="0"> 
     <ImageView 
      android:id="@+id/ivExampleImg" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:contentDescription="Big scrollable image" 
      android:src="@drawable/exampleimg" /> 
    </HorizontalScrollView> 
</RelativeLayout> 

답변

0

당신 되풀이 할 모든 뷰/레이아웃에 wrap_content를 설정해보십시오 ...

+0

LinearLayout 상위를 제외한 모든보기에서 너비가 wrap_content로 설정됩니다. 높이는 화면 높이 s와 동일해야합니다. o ImageView와 horizontalScrollView에 대해 fill_parent로 설정했습니다. – anderfo

+0

따라서 이미지 뷰의 부모/너비와 동일한 너비/높이를 얻으려면 선형 레이아웃을 사용하고 상대적인 거리를 사용하십시오. – ChristopheCVB

+0

나머지 모든 공간은 선형 레이아웃에 채워 지므로 이미지 뷰는 사용 가능한 모든 공간을 차지합니다. – ChristopheCVB

0

이 대답은 나를 위해 작동합니다 : 당신은 그냥 설정해야합니다, 기본적으로 Massive unwanted whitespace with LinearLayout in ScrollView

ImageView의 adjustViewBounds를 true로 설정하면 다음과 같이됩니다.

  <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:adjustViewBounds="true"/> 
+0

죄송합니다.하지만 그렇게하면 아무런 효과가 없습니다 ... – anderfo