我有一个垂直的大图像,我想让它可滚动。 我已经这样做了,
<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 :(得分:0)
尝试此操作(此代码来自一个Activity,后端包含一个名为'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"
/>
答案 1 :(得分: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>
答案 2 :(得分:0)
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
答案 3 :(得分: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;
}
});
}
完美地完成了我的工作...水平&amp;包括垂直滚动(已启用)