translate matrix is not working in android

859 Views Asked by At

I'm using Matrix and Bitmap for imageView, I want to setup position and Scaling for image as imageView. (imageView is always showed x = 0, y = 0 ) Scalling is worked , but translate position is not working. Please help me regarding this. here is my code

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View root = inflater.inflate(R.layout.fragment_entrance, container);
        ImageButton setting_button = (ImageButton) root.findViewById(R.id.settings_next);
        setting_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), LoginActivity.class);
                intent.putExtra("next_page", false);
                startActivity(intent);
            }
        });
        final ImageView backGroundImageView = (ImageView) root.findViewById(R.id.fragment_entrance_background_imageview);
        mLogoImageView = (ImageView) root.findViewById(R.id.fragment_entrance_logo_imageview);


        Matrix mMatrix = new Matrix();
        mMatrix.reset();
        mMatrix.postTranslate(mCenterX - mImgWidth*0.5f, mCenterY - mImgHeight * 0.5f);
        mMatrix.postScale(mScaleX, mScaleY, mCenterX, mCenterY);
        mLogoImageView.invalidate();
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), mLogoImgId);
        Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, (int) mImgWidth, (int) mImgHeight, mMatrix, true);

        mLogoImageView.setImageBitmap(newBitmap);
        return root;
    }

and here is xml file.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/entrance"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0099cc"
    tools:context="com.receptionist.receptionist.Entrance.EntranceFragment">

    <ImageView
        android:id="@+id/fragment_entrance_background_imageview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="0dp"
        android:padding="0dp">

        <ImageView
            android:id="@+id/fragment_entrance_logo_imageview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="matrix"/>
    </RelativeLayout>

    <ImageView
        android:id="@+id/dummy_button"
        android:layout_width="111dp"
        android:layout_height="94dp"
        android:layout_gravity="center|bottom"
        android:layout_marginBottom="40dp"
        android:background="@color/black_overlay"
        android:src="@drawable/button_next" />

    <ImageButton
        android:id="@+id/settings_next"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_gravity="right|top"
        android:background="@color/black_overlay"
        android:src="@drawable/setting_w" />


</FrameLayout>
0

There are 0 best solutions below