【发布时间】:2018-08-07 21:29:56
【问题描述】:
我想在 TextView 和 ImageView 上设置缩放控件。其中,当按下放大时,所有 textview 和 imageview 都被放大,当按下缩小时,所有 textview 和 imageview 都被缩小,并具有左右滚动功能。 或者,是否可以仅在图像视图中缩放? 我的尝试如下,但效果不佳。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activity_main"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:orientation="vertical"
tools:context="sample.app"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:orientation="vertical"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:textIsSelectable="true"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="something in text view"
android:textColor="#ff0000"
android:textIsSelectable="true"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="another textview"
android:textColor="#000000"
android:textIsSelectable="true"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Parts list"
android:textColor="#ff0000"
android:textIsSelectable="true"
android:textSize="20dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="@drawable/melody" />
</LinearLayout>
</ScrollView>
<ZoomControls
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/zoomControls"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
public class melodygenerator extends AppCompatActivity {
ZoomControls zoomit;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.melodygenerator);
zoomit = (ZoomControls)findViewById(R.id.zoomControls);
imageView = (ImageView)findViewById(R.id.imageView);
zoomit.setOnZoomInClickListener(new View.OnClickListener(){
@Override
public void onClick(View V){
float x = imageView.getScaleX();
float y = imageView.getScrollY();
imageView.setScaleX ((int) (x+1));
imageView.setScaleY((int) (y+1));
}
});
zoomit.setOnZoomOutClickListener(new View.OnClickListener() {
@Override
public void onClick(View V) {
float x = imageView.getScaleX();
float y = imageView.getScrollY();
imageView.setScaleX ((int) (x-1));
imageView.setScaleY((int) (y-1));
}
});
}}
【问题讨论】:
标签: android imageview pinchzoom zooming