2017-02-06 2 views
0

J'ai une grande image verticale, je veux la faire défiler. Je l'ai fait comme ça,Big Image Vertical Scroll

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/logoimage" 
      android:scrollbarAlwaysDrawVerticalTrack="true" > 

     <ImageView 
      android:contentDescription="Specs" 
      android:adjustViewBounds="true" 
      android:id="@+id/imageScroll" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical" 
      android:src="@drawable/rules" > 
     </ImageView> 
     </ScrollView> 

Mais ça ne marche pas montre en bonne mise en page, mais il n'affiche pas quand je commence l'activité

<RelativeLayout 
     android:id="@+id/linear1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#172027" 
     android:orientation="horizontal" 
     android:visibility="visible"> 
     <ImageView 
      android:layout_width="@dimen/logoSize" 
      android:layout_height="@dimen/logoSizeH" 
      android:src="@drawable/logocopy" 
      android:layout_marginTop="25dp" 
      android:id="@+id/logoimage" 
      android:layout_marginLeft="20dp"/> 
     <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/logoimage" 
      android:background="@drawable/rules" 
      android:scrollbarAlwaysDrawVerticalTrack="true" > 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
       <ImageView 
        android:adjustViewBounds="true" 
        android:id="@+id/imageScroll" 
        android:layout_width="match_parent" 
        android:fillViewport="true" 
        android:layout_height="wrap_content" 
        android:scrollbars="vertical" 
        android:src="@drawable/rules" 
        android:scaleType="centerCrop" > 
       </ImageView> 

      </LinearLayout> 
     </ScrollView> 




     <RelativeLayout 
      android:id="@+id/humburger_main1" 
      android:layout_width="wrap_content" 
      android:layout_height="50dp" 
      android:layout_marginTop="30dp" 
      android:layout_marginRight="20dp" 
      android:layout_alignParentEnd="true" 
      android:gravity="center" 
      android:orientation="vertical" 
      android:layout_alignParentRight="true"> 

      <LinearLayout 
       android:id="@+id/humburger_31" 
       android:layout_width="30dp" 
       android:layout_height="5dp" 
       android:background="#ffff" 
       android:orientation="horizontal" /> 


      <LinearLayout 
       android:id="@+id/humburger_11" 
       android:layout_width="30dp" 
       android:layout_height="5dp" 
       android:layout_below="@+id/humburger_31" 
       android:layout_marginTop="10dp" 
       android:background="#ffff" 
       android:orientation="horizontal" /> 

      <LinearLayout 
       android:id="@+id/humburger_21" 
       android:layout_width="30dp" 
       android:layout_height="5dp" 
       android:layout_below="@+id/humburger_31" 
       android:layout_marginTop="10dp" 
       android:background="#ffff" 
       android:orientation="horizontal" /> 

      <LinearLayout 
       android:id="@+id/humburger_41" 
       android:layout_width="30dp" 
       android:layout_height="5dp" 
       android:layout_below="@+id/humburger_21" 
       android:layout_marginTop="10dp" 
       android:background="#ffff" 
       android:orientation="horizontal" /> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </RelativeLayout> 
     <LinearLayout 
      android:id="@+id/RecyclerView1" 
      android:layout_width="20dp" 
      android:layout_height="match_parent" 
      android:layout_alignParentRight="true" 
      android:background="#00ff0000" 
      android:orientation="horizontal" 
      android:scrollbars="vertical"> 

     </LinearLayout> 

    </RelativeLayout> 

est ici le code xml qui est dans l'activité est défile, mais l'image ne montre pas

+0

Vous ne voulez pas non plus le défilement horizontal? – tahsinRupam

Répondre

0

Essayez ceci (ce code est d'une activité qui a un fichier xml sur le back-end contenant un ImageView appelé « img »)

<ImageView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/img" 
android:scaleType="center" 
android:background="#fff" 
android:src="@drawable/picName" 
/> 
0

Essayez de changer ImageView code comme ceci:

<ImageView 
     android:contentDescription="Specs" 
     android:adjustViewBounds="true" 
     android:id="@+id/imageScroll" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="vertical" 
     android:src="@drawable/rules" 
     android:scaleType="fitXY" > 

Update 1

Sinon, vous pouvez peut-être essayer quelque chose comme ceci:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/logoimage"> 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="0dp"> 

     <ImageView 
      android:contentDescription="Specs" 
      android:adjustViewBounds="true" 
      android:id="@+id/imageScroll" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/rules" 
      android:layout_marginTop="0dp" > 
     </ImageView> 
    </LinearLayout> 
</ScrollView> 

Mise à jour 2

Je ne suis pas sûr que cela fonctionnera, mais essayez de changer votre mise en page à ce ci-dessous:

<RelativeLayout 
    android:id="@+id/linear1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#172027" 
    android:visibility="visible"> 
    <ImageView 
     android:layout_width="@dimen/logoSize" 
     android:layout_height="@dimen/logoSizeH" 
     android:src="@drawable/logocopy" 
     android:layout_marginTop="25dp" 
     android:layout_alignParentTop="true" 
     android:id="@+id/logoimage" 
     android:layout_marginLeft="20dp"/> 
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/scrollview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/logoimage" 
     android:background="@drawable/rules" 
     android:scrollbarAlwaysDrawVerticalTrack="true" > 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <ImageView 
       android:adjustViewBounds="true" 
       android:id="@+id/imageScroll" 
       android:layout_width="match_parent" 
       android:fillViewport="true" 
       android:layout_height="wrap_content" 
       android:scrollbars="vertical" 
       android:src="@drawable/rules" 
       android:scaleType="center" > 
      </ImageView> 

     </LinearLayout> 
    </ScrollView> 

    <RelativeLayout 
     android:id="@+id/humburger_main1" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_marginTop="30dp" 
     android:layout_marginRight="20dp" 
     android:layout_alignParentEnd="true" 
     android:gravity="center" 
     android:layout_alignParentRight="true" 
     android:layout_toRightOf="@id/scrollview"> 

     <LinearLayout 
      android:id="@+id/humburger_31" 
      android:layout_width="30dp" 
      android:layout_height="5dp" 
      android:background="#ffff" 
      android:orientation="horizontal" /> 

     <LinearLayout 
      android:id="@+id/humburger_11" 
      android:layout_width="30dp" 
      android:layout_height="5dp" 
      android:layout_below="@+id/humburger_31" 
      android:layout_marginTop="10dp" 
      android:background="#ffff" 
      android:orientation="horizontal" /> 

     <LinearLayout 
      android:id="@+id/humburger_21" 
      android:layout_width="30dp" 
      android:layout_height="5dp" 
      android:layout_below="@+id/humburger_31" 
      android:layout_marginTop="10dp" 
      android:background="#ffff" 
      android:orientation="horizontal" /> 

     <LinearLayout 
      android:id="@+id/humburger_41" 
      android:layout_width="30dp" 
      android:layout_height="5dp" 
      android:layout_below="@+id/humburger_21" 
      android:layout_marginTop="10dp" 
      android:background="#ffff" 
      android:orientation="horizontal" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </RelativeLayout> 
    <LinearLayout 
     android:id="@+id/RecyclerView1" 
     android:layout_width="20dp" 
     android:layout_height="match_parent" 
     android:layout_alignParentRight="true" 
     android_layout_toRightOf="@id/scrollview" 
     android:background="#00ff0000" 
     android:orientation="horizontal" 
     android:scrollbars="vertical"> 

    </LinearLayout> 

</RelativeLayout> 
+0

cela ne fonctionne pas ... – Vladimir

+0

si vous modifiez la propriété android: layout_height de ScrollView à match_parent? –

+0

Pouvez-vous poster le code de l'ensemble du fichier XML de mise en page? –

0

désolé mais avez-vous mis cette disposition dans votre activité? utilisez cette mise en page simple au lieu de la vôtre.

<ScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

</ScrollView> 
+0

ofc Je l'ai mis à l'activité – Vladimir

+0

s'il vous plaît envoyez votre code d'activité. Si ma réponse et d'autres ne m'a pas dérangé, je pense qu'il n'y a rien de mal avec xml en ce qui me concerne. –

+0

setContentView (R.layout.activity_savefty); omg Je ne regarde pas le contenu que veux-tu? – Vladimir

0

J'ai cherché si longtemps cette question et enfin trouver ce code:

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/img" 
    android:scaleType="center" 
    android:background="#fff" 
    android:src="@drawable/picName"/> 

et aussi ce

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

    setContentView(R.layout.xml_name_layout); 

    final ImageView switcherView = (ImageView)this.findViewById(R.id.img); 

    switcherView.setOnTouchListener(new View.OnTouchListener() 
    { 

     public boolean onTouch(View arg0, MotionEvent event) 
     { 

      float curX, curY; 

      switch (event.getAction()) 
      { 

       case MotionEvent.ACTION_DOWN: 
        mx = event.getX(); 
        my = event.getY(); 
        break; 
       case MotionEvent.ACTION_MOVE: 
        curX = event.getX(); 
        curY = event.getY(); 
        switcherView.scrollBy((int) (mx - curX), (int) (my - curY)); 
        mx = curX; 
        my = curY; 
        break; 
       case MotionEvent.ACTION_UP: 
        curX = event.getX(); 
        curY = event.getY(); 
        switcherView.scrollBy((int) (mx - curX), (int) (my - curY)); 
        break; 
      } 

      return true; 
     } 
    }); 
} 

a fait le travail parfaitement pour moi ... horizontal & défilement vertical inclus (activé)