android studio zoom image in + horizo​​ntal scrolling

时间:2018-02-21 09:39:24

标签: android

我正在开发一个Android项目,为此我有一个人体模型图像:

enter image description here

我想直接放大,以便您只能看到一个人体模型,例如中间的一个开始,然后在图像的两侧有两个箭头,然后单击左箭头查看左侧人体模型,右侧看到正确的人体模型。

这是我的尝试,但不起作用

布局活动:

<?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:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_home_page"
tools:context="com.example.lahirufernando.skinsensor.HomePage"
android:background="#e0e0e0">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/textViewBottom"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:background="@drawable/peace" />

<ImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="350dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_centerVertical="true"
    android:background="@drawable/loginbox" />


<Button
    android:id="@+id/ibLeft"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:background="@drawable/left_arrow" />

<Button
    android:id="@+id/ibRight"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView"
    android:layout_alignLeft="@+id/questionBtn"
    android:layout_alignStart="@+id/questionBtn"
    android:background="@drawable/right_arrow" />

<HorizontalScrollView
    android:id="@+id/hsv"
    android:layout_width="wrap_content"
    android:fadingEdgeLength="100dp"
    android:layout_toRightOf="@id/ibLeft"
    android:layout_toLeftOf="@id/ibRight"
    android:layout_height="wrap_content" >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/humanbody"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:scaleType="centerCrop"
            android:background="@null" />

    </LinearLayout>

</HorizontalScrollView>

<TextView
    android:id="@+id/textViewBottom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="10dp"
    android:textColor="#FFFF"
    android:text="Tip: You can zoom in and turn your device!"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/questionBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"


    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/bodyPart"
    android:layout_marginEnd="40dp"
    android:layout_marginRight="40dp"
    android:layout_marginTop="35dp"
    android:clickable="true"
    app:backgroundTint="#FFFF"
    app:fabSize="mini"
    app:srcCompat="@drawable/question" />

<TextView
    android:id="@+id/bodyPart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="18dp"
    android:text="Click a Body Region"
    android:textColor="#000000"
    android:textSize="20dp" />

活性

private final String TAG = getClass().getSimpleName();
HorizontalScrollView hSV;
Button ibLeft,ibRight;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_page);
    FloatingActionButton homeBtn = (FloatingActionButton) findViewById(R.id.homeButton);
    FloatingActionButton questionButton = (FloatingActionButton) findViewById(R.id.questionBtn);
    hSV = (HorizontalScrollView) findViewById(R.id.hsv);

    ibLeft=(Button) findViewById(R.id.ibLeft);
    ibLeft.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            hSV.scrollTo((int)hSV.getScrollX() - 10, (int)hSV.getScrollY());
        }
    });

    ibRight=(Button) findViewById(R.id.ibRight);
    ibLeft.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            hSV.scrollTo((int)hSV.getScrollX() + 10, (int)hSV.getScrollY());
        }
    });



    // Add image
    ImageView image = (ImageView) findViewById(R.id.imageView);
    image.setImageResource(R.drawable.human);

0 个答案:

没有答案