How to move Image to position x, y coordinate with current scale and padding
I am using Photoview Library in my project. I need to setPadding in Imageview with Zoom.
When I use with left and top padding, It working Perfectly. It also move image from left and top as I wish.
mPhotoView.setPadding(150, 150, 0, 0);
But, When I apply right padding and bottom padding , it apply padding but not automatically move from current place.
mPhotoView.setPadding(0, 0, 150, 150); //Issue here.
android android-layout android-imageview android-photoview
add a comment |
I am using Photoview Library in my project. I need to setPadding in Imageview with Zoom.
When I use with left and top padding, It working Perfectly. It also move image from left and top as I wish.
mPhotoView.setPadding(150, 150, 0, 0);
But, When I apply right padding and bottom padding , it apply padding but not automatically move from current place.
mPhotoView.setPadding(0, 0, 150, 150); //Issue here.
android android-layout android-imageview android-photoview
add a comment |
I am using Photoview Library in my project. I need to setPadding in Imageview with Zoom.
When I use with left and top padding, It working Perfectly. It also move image from left and top as I wish.
mPhotoView.setPadding(150, 150, 0, 0);
But, When I apply right padding and bottom padding , it apply padding but not automatically move from current place.
mPhotoView.setPadding(0, 0, 150, 150); //Issue here.
android android-layout android-imageview android-photoview
I am using Photoview Library in my project. I need to setPadding in Imageview with Zoom.
When I use with left and top padding, It working Perfectly. It also move image from left and top as I wish.
mPhotoView.setPadding(150, 150, 0, 0);
But, When I apply right padding and bottom padding , it apply padding but not automatically move from current place.
mPhotoView.setPadding(0, 0, 150, 150); //Issue here.
android android-layout android-imageview android-photoview
android android-layout android-imageview android-photoview
edited Nov 29 '18 at 7:00
Nilesh Rathod
31.7k82956
31.7k82956
asked Nov 22 '18 at 13:19
Abhay KoradiyaAbhay Koradiya
7961323
7961323
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You need to use requestLayout()
after setting padding in your mPhotoView
public void requestLayout ()
Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.
SAMPLE CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:onClick="ClickMe3"
android:text="Remove Padding " />
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:onClick="ClickMe"
android:text="left and top " />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:onClick="ClickMe2"
android:text="right and bottom " />
</RelativeLayout>
Activity Code
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.github.chrisbanes.photoview.PhotoView;
public class MainActivity extends AppCompatActivity {
PhotoView mPhotoView;
boolean flag = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPhotoView = (PhotoView) findViewById(R.id.photo_view);
mPhotoView.setImageResource(R.drawable.dishu);
}
public void ClickMe(View view) {
mPhotoView.setPadding(150, 150, 0, 0);
mPhotoView.requestLayout();
}
public void ClickMe2(View view) {
mPhotoView.setPadding(0, 0, 150, 150);
mPhotoView.requestLayout();
}
public void ClickMe3(View view) {
mPhotoView.setPadding(0, 0, 0, 0);
mPhotoView.requestLayout();
}
}
Please check the output of the above code https://www.youtube.com/watch?v=828XI6ydNdY
UPDATE
as per your below comment
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
Actually Your padding Right and Bottom is working
after setting padding you need to scroll your mPhotoView
Like below code
public class MainActivity extends AppCompatActivity {
PhotoView mPhotoView;
RelativeLayout rootView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rootView = findViewById(R.id.rootView);
mPhotoView = (PhotoView) findViewById(R.id.photo_view);
mPhotoView.setImageResource(R.drawable.dishu);
}
public void Left_Top(View view) {
mPhotoView.setPadding(150, 150, 0, 0);
mPhotoView.requestLayout();
}
public void Right_Bottom(View view) {
mPhotoView.setPadding(0, 0, 150, 150);
mPhotoView.requestLayout();
// after setting padding scroll your mPhotoView to bottom
mPhotoView.scrollTo(150,150);
}
public void ClickMe3(View view) {
mPhotoView.setPadding(0, 0, 0, 0);
mPhotoView.requestLayout();
mPhotoView.scrollTo(0,0);
}
}
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
– Abhay Koradiya
Nov 28 '18 at 7:03
@AbhayKoradiya it actually setting padding after applying padding try to scroll image
– Nilesh Rathod
Nov 28 '18 at 7:14
Yes It scrolls Perfectly, even I don't write requestlayout.
– Abhay Koradiya
Nov 28 '18 at 7:14
But, I want effect like left padding (Auto scrolling).
– Abhay Koradiya
Nov 28 '18 at 7:15
@AbhayKoradiya wait i will update my answer
– Nilesh Rathod
Nov 28 '18 at 7:17
|
show 2 more comments
You can use Parent Layout (LinearLayout
or FramLayout
)to apply your padding on and put your ImageView
in it so its work according your requirements.
OR
You can use ScaleType
property so it can be manage in a smooth way.
I want to zoom Imageview with out of boundry. so it can't help me.
– Abhay Koradiya
Nov 28 '18 at 7:05
add a comment |
You need to use constraints, put it in a ConstraintLayout
and then set the edges to 0, or set the Constraint to how much you want it to not shift.
https://medium.com/@eugenebrusov/using-of-constraintlayout-to-set-your-imageview-in-16-9-ratio-9979d53ba976
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431919%2fhow-to-move-image-to-position-x-y-coordinate-with-current-scale-and-padding%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to use requestLayout()
after setting padding in your mPhotoView
public void requestLayout ()
Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.
SAMPLE CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:onClick="ClickMe3"
android:text="Remove Padding " />
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:onClick="ClickMe"
android:text="left and top " />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:onClick="ClickMe2"
android:text="right and bottom " />
</RelativeLayout>
Activity Code
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.github.chrisbanes.photoview.PhotoView;
public class MainActivity extends AppCompatActivity {
PhotoView mPhotoView;
boolean flag = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPhotoView = (PhotoView) findViewById(R.id.photo_view);
mPhotoView.setImageResource(R.drawable.dishu);
}
public void ClickMe(View view) {
mPhotoView.setPadding(150, 150, 0, 0);
mPhotoView.requestLayout();
}
public void ClickMe2(View view) {
mPhotoView.setPadding(0, 0, 150, 150);
mPhotoView.requestLayout();
}
public void ClickMe3(View view) {
mPhotoView.setPadding(0, 0, 0, 0);
mPhotoView.requestLayout();
}
}
Please check the output of the above code https://www.youtube.com/watch?v=828XI6ydNdY
UPDATE
as per your below comment
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
Actually Your padding Right and Bottom is working
after setting padding you need to scroll your mPhotoView
Like below code
public class MainActivity extends AppCompatActivity {
PhotoView mPhotoView;
RelativeLayout rootView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rootView = findViewById(R.id.rootView);
mPhotoView = (PhotoView) findViewById(R.id.photo_view);
mPhotoView.setImageResource(R.drawable.dishu);
}
public void Left_Top(View view) {
mPhotoView.setPadding(150, 150, 0, 0);
mPhotoView.requestLayout();
}
public void Right_Bottom(View view) {
mPhotoView.setPadding(0, 0, 150, 150);
mPhotoView.requestLayout();
// after setting padding scroll your mPhotoView to bottom
mPhotoView.scrollTo(150,150);
}
public void ClickMe3(View view) {
mPhotoView.setPadding(0, 0, 0, 0);
mPhotoView.requestLayout();
mPhotoView.scrollTo(0,0);
}
}
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
– Abhay Koradiya
Nov 28 '18 at 7:03
@AbhayKoradiya it actually setting padding after applying padding try to scroll image
– Nilesh Rathod
Nov 28 '18 at 7:14
Yes It scrolls Perfectly, even I don't write requestlayout.
– Abhay Koradiya
Nov 28 '18 at 7:14
But, I want effect like left padding (Auto scrolling).
– Abhay Koradiya
Nov 28 '18 at 7:15
@AbhayKoradiya wait i will update my answer
– Nilesh Rathod
Nov 28 '18 at 7:17
|
show 2 more comments
You need to use requestLayout()
after setting padding in your mPhotoView
public void requestLayout ()
Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.
SAMPLE CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:onClick="ClickMe3"
android:text="Remove Padding " />
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:onClick="ClickMe"
android:text="left and top " />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:onClick="ClickMe2"
android:text="right and bottom " />
</RelativeLayout>
Activity Code
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.github.chrisbanes.photoview.PhotoView;
public class MainActivity extends AppCompatActivity {
PhotoView mPhotoView;
boolean flag = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPhotoView = (PhotoView) findViewById(R.id.photo_view);
mPhotoView.setImageResource(R.drawable.dishu);
}
public void ClickMe(View view) {
mPhotoView.setPadding(150, 150, 0, 0);
mPhotoView.requestLayout();
}
public void ClickMe2(View view) {
mPhotoView.setPadding(0, 0, 150, 150);
mPhotoView.requestLayout();
}
public void ClickMe3(View view) {
mPhotoView.setPadding(0, 0, 0, 0);
mPhotoView.requestLayout();
}
}
Please check the output of the above code https://www.youtube.com/watch?v=828XI6ydNdY
UPDATE
as per your below comment
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
Actually Your padding Right and Bottom is working
after setting padding you need to scroll your mPhotoView
Like below code
public class MainActivity extends AppCompatActivity {
PhotoView mPhotoView;
RelativeLayout rootView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rootView = findViewById(R.id.rootView);
mPhotoView = (PhotoView) findViewById(R.id.photo_view);
mPhotoView.setImageResource(R.drawable.dishu);
}
public void Left_Top(View view) {
mPhotoView.setPadding(150, 150, 0, 0);
mPhotoView.requestLayout();
}
public void Right_Bottom(View view) {
mPhotoView.setPadding(0, 0, 150, 150);
mPhotoView.requestLayout();
// after setting padding scroll your mPhotoView to bottom
mPhotoView.scrollTo(150,150);
}
public void ClickMe3(View view) {
mPhotoView.setPadding(0, 0, 0, 0);
mPhotoView.requestLayout();
mPhotoView.scrollTo(0,0);
}
}
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
– Abhay Koradiya
Nov 28 '18 at 7:03
@AbhayKoradiya it actually setting padding after applying padding try to scroll image
– Nilesh Rathod
Nov 28 '18 at 7:14
Yes It scrolls Perfectly, even I don't write requestlayout.
– Abhay Koradiya
Nov 28 '18 at 7:14
But, I want effect like left padding (Auto scrolling).
– Abhay Koradiya
Nov 28 '18 at 7:15
@AbhayKoradiya wait i will update my answer
– Nilesh Rathod
Nov 28 '18 at 7:17
|
show 2 more comments
You need to use requestLayout()
after setting padding in your mPhotoView
public void requestLayout ()
Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.
SAMPLE CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:onClick="ClickMe3"
android:text="Remove Padding " />
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:onClick="ClickMe"
android:text="left and top " />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:onClick="ClickMe2"
android:text="right and bottom " />
</RelativeLayout>
Activity Code
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.github.chrisbanes.photoview.PhotoView;
public class MainActivity extends AppCompatActivity {
PhotoView mPhotoView;
boolean flag = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPhotoView = (PhotoView) findViewById(R.id.photo_view);
mPhotoView.setImageResource(R.drawable.dishu);
}
public void ClickMe(View view) {
mPhotoView.setPadding(150, 150, 0, 0);
mPhotoView.requestLayout();
}
public void ClickMe2(View view) {
mPhotoView.setPadding(0, 0, 150, 150);
mPhotoView.requestLayout();
}
public void ClickMe3(View view) {
mPhotoView.setPadding(0, 0, 0, 0);
mPhotoView.requestLayout();
}
}
Please check the output of the above code https://www.youtube.com/watch?v=828XI6ydNdY
UPDATE
as per your below comment
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
Actually Your padding Right and Bottom is working
after setting padding you need to scroll your mPhotoView
Like below code
public class MainActivity extends AppCompatActivity {
PhotoView mPhotoView;
RelativeLayout rootView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rootView = findViewById(R.id.rootView);
mPhotoView = (PhotoView) findViewById(R.id.photo_view);
mPhotoView.setImageResource(R.drawable.dishu);
}
public void Left_Top(View view) {
mPhotoView.setPadding(150, 150, 0, 0);
mPhotoView.requestLayout();
}
public void Right_Bottom(View view) {
mPhotoView.setPadding(0, 0, 150, 150);
mPhotoView.requestLayout();
// after setting padding scroll your mPhotoView to bottom
mPhotoView.scrollTo(150,150);
}
public void ClickMe3(View view) {
mPhotoView.setPadding(0, 0, 0, 0);
mPhotoView.requestLayout();
mPhotoView.scrollTo(0,0);
}
}
You need to use requestLayout()
after setting padding in your mPhotoView
public void requestLayout ()
Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.
SAMPLE CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:onClick="ClickMe3"
android:text="Remove Padding " />
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:onClick="ClickMe"
android:text="left and top " />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:onClick="ClickMe2"
android:text="right and bottom " />
</RelativeLayout>
Activity Code
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.github.chrisbanes.photoview.PhotoView;
public class MainActivity extends AppCompatActivity {
PhotoView mPhotoView;
boolean flag = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPhotoView = (PhotoView) findViewById(R.id.photo_view);
mPhotoView.setImageResource(R.drawable.dishu);
}
public void ClickMe(View view) {
mPhotoView.setPadding(150, 150, 0, 0);
mPhotoView.requestLayout();
}
public void ClickMe2(View view) {
mPhotoView.setPadding(0, 0, 150, 150);
mPhotoView.requestLayout();
}
public void ClickMe3(View view) {
mPhotoView.setPadding(0, 0, 0, 0);
mPhotoView.requestLayout();
}
}
Please check the output of the above code https://www.youtube.com/watch?v=828XI6ydNdY
UPDATE
as per your below comment
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
Actually Your padding Right and Bottom is working
after setting padding you need to scroll your mPhotoView
Like below code
public class MainActivity extends AppCompatActivity {
PhotoView mPhotoView;
RelativeLayout rootView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rootView = findViewById(R.id.rootView);
mPhotoView = (PhotoView) findViewById(R.id.photo_view);
mPhotoView.setImageResource(R.drawable.dishu);
}
public void Left_Top(View view) {
mPhotoView.setPadding(150, 150, 0, 0);
mPhotoView.requestLayout();
}
public void Right_Bottom(View view) {
mPhotoView.setPadding(0, 0, 150, 150);
mPhotoView.requestLayout();
// after setting padding scroll your mPhotoView to bottom
mPhotoView.scrollTo(150,150);
}
public void ClickMe3(View view) {
mPhotoView.setPadding(0, 0, 0, 0);
mPhotoView.requestLayout();
mPhotoView.scrollTo(0,0);
}
}
edited Nov 28 '18 at 9:30
answered Nov 28 '18 at 5:42
Nilesh RathodNilesh Rathod
31.7k82956
31.7k82956
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
– Abhay Koradiya
Nov 28 '18 at 7:03
@AbhayKoradiya it actually setting padding after applying padding try to scroll image
– Nilesh Rathod
Nov 28 '18 at 7:14
Yes It scrolls Perfectly, even I don't write requestlayout.
– Abhay Koradiya
Nov 28 '18 at 7:14
But, I want effect like left padding (Auto scrolling).
– Abhay Koradiya
Nov 28 '18 at 7:15
@AbhayKoradiya wait i will update my answer
– Nilesh Rathod
Nov 28 '18 at 7:17
|
show 2 more comments
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
– Abhay Koradiya
Nov 28 '18 at 7:03
@AbhayKoradiya it actually setting padding after applying padding try to scroll image
– Nilesh Rathod
Nov 28 '18 at 7:14
Yes It scrolls Perfectly, even I don't write requestlayout.
– Abhay Koradiya
Nov 28 '18 at 7:14
But, I want effect like left padding (Auto scrolling).
– Abhay Koradiya
Nov 28 '18 at 7:15
@AbhayKoradiya wait i will update my answer
– Nilesh Rathod
Nov 28 '18 at 7:17
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
– Abhay Koradiya
Nov 28 '18 at 7:03
My ImageView with FItXY scaletype. When I apply your code , Not working. same result. It can't move automatic as left padding.
– Abhay Koradiya
Nov 28 '18 at 7:03
@AbhayKoradiya it actually setting padding after applying padding try to scroll image
– Nilesh Rathod
Nov 28 '18 at 7:14
@AbhayKoradiya it actually setting padding after applying padding try to scroll image
– Nilesh Rathod
Nov 28 '18 at 7:14
Yes It scrolls Perfectly, even I don't write requestlayout.
– Abhay Koradiya
Nov 28 '18 at 7:14
Yes It scrolls Perfectly, even I don't write requestlayout.
– Abhay Koradiya
Nov 28 '18 at 7:14
But, I want effect like left padding (Auto scrolling).
– Abhay Koradiya
Nov 28 '18 at 7:15
But, I want effect like left padding (Auto scrolling).
– Abhay Koradiya
Nov 28 '18 at 7:15
@AbhayKoradiya wait i will update my answer
– Nilesh Rathod
Nov 28 '18 at 7:17
@AbhayKoradiya wait i will update my answer
– Nilesh Rathod
Nov 28 '18 at 7:17
|
show 2 more comments
You can use Parent Layout (LinearLayout
or FramLayout
)to apply your padding on and put your ImageView
in it so its work according your requirements.
OR
You can use ScaleType
property so it can be manage in a smooth way.
I want to zoom Imageview with out of boundry. so it can't help me.
– Abhay Koradiya
Nov 28 '18 at 7:05
add a comment |
You can use Parent Layout (LinearLayout
or FramLayout
)to apply your padding on and put your ImageView
in it so its work according your requirements.
OR
You can use ScaleType
property so it can be manage in a smooth way.
I want to zoom Imageview with out of boundry. so it can't help me.
– Abhay Koradiya
Nov 28 '18 at 7:05
add a comment |
You can use Parent Layout (LinearLayout
or FramLayout
)to apply your padding on and put your ImageView
in it so its work according your requirements.
OR
You can use ScaleType
property so it can be manage in a smooth way.
You can use Parent Layout (LinearLayout
or FramLayout
)to apply your padding on and put your ImageView
in it so its work according your requirements.
OR
You can use ScaleType
property so it can be manage in a smooth way.
answered Nov 28 '18 at 5:09
Chetan JoshiChetan Joshi
3,59111520
3,59111520
I want to zoom Imageview with out of boundry. so it can't help me.
– Abhay Koradiya
Nov 28 '18 at 7:05
add a comment |
I want to zoom Imageview with out of boundry. so it can't help me.
– Abhay Koradiya
Nov 28 '18 at 7:05
I want to zoom Imageview with out of boundry. so it can't help me.
– Abhay Koradiya
Nov 28 '18 at 7:05
I want to zoom Imageview with out of boundry. so it can't help me.
– Abhay Koradiya
Nov 28 '18 at 7:05
add a comment |
You need to use constraints, put it in a ConstraintLayout
and then set the edges to 0, or set the Constraint to how much you want it to not shift.
https://medium.com/@eugenebrusov/using-of-constraintlayout-to-set-your-imageview-in-16-9-ratio-9979d53ba976
add a comment |
You need to use constraints, put it in a ConstraintLayout
and then set the edges to 0, or set the Constraint to how much you want it to not shift.
https://medium.com/@eugenebrusov/using-of-constraintlayout-to-set-your-imageview-in-16-9-ratio-9979d53ba976
add a comment |
You need to use constraints, put it in a ConstraintLayout
and then set the edges to 0, or set the Constraint to how much you want it to not shift.
https://medium.com/@eugenebrusov/using-of-constraintlayout-to-set-your-imageview-in-16-9-ratio-9979d53ba976
You need to use constraints, put it in a ConstraintLayout
and then set the edges to 0, or set the Constraint to how much you want it to not shift.
https://medium.com/@eugenebrusov/using-of-constraintlayout-to-set-your-imageview-in-16-9-ratio-9979d53ba976
edited Nov 28 '18 at 5:13
Chetan Joshi
3,59111520
3,59111520
answered Nov 28 '18 at 4:57
Kingsley MitchellKingsley Mitchell
575418
575418
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431919%2fhow-to-move-image-to-position-x-y-coordinate-with-current-scale-and-padding%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown