2017-02-06 137 views
0

我有一个垂直的大图像,我想让它滚动。 我做了像这样,大图垂直滚动

<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> 

但它不工作,它显示的布局不错,但是当我开始活动

<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> 

这里不显示的XML代码即在活性是滚动而图像不显示

+0

你不想水平滚动吗? – tahsinRupam

回答

0

尝试此(此代码是从一个活动,其具有所谓的“IMG”上含有的ImageView后端一个XML文件)

<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

试图改变ImageView这样的代码:

<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" > 

更新1

或者也许你可以尝试这样的事:

<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> 

更新2

我不知道它会工作,但要尽量布局改变这个如下:

<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

这是行不通的... – Vladimir

+0

如果您将ScrollView的android:layout_height属性更改为match_parent? –

+0

你可以发布整个布局xml文件的代码吗? –

0

抱歉,但没有u盘这种布局在您的活动? 使用这个简单的布局,而不是你的。

<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我确实设置了活动 – Vladimir

+0

请发送您的活动代码。如果我的回答和其他问题没有解决,我认为就我而言,xml没有任何问题。 –

+0

setContentView(R.layout.activity_savefty); omg我设定内容查看你想要什么? – Vladimir

0

我搜索了这个问题这么久,终于找到这个代码:

<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"/> 

而且这个

@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; 
     } 
    }); 
} 

完全做的工作对我来说...水平&垂直滚动包括(启用)