ImageView- resize depending on android screen - java

I have a problem and I can't solve it, I will appreciate it if somebody would help me. I want to put two images on the top of the screen. Both images should have width = screen_width/2 (just because when the screen is smaller, images should resize).I've tried this, but it isn't enough. Thank you!
<RelativeLayout
android:id="#+id/imagelayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/r"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="3dp"
android:background="#drawable/back" />
<TextView
android:id="#+id/resulttext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textStyle="bold"
android:text="Hello"
android:layout_alignLeft="#id/r"
android:layout_alignTop="#id/r"
android:layout_alignRight="#id/r"
android:layout_alignBottom="#id/r"/>
</RelativeLayout>

For reference : http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0CC0QtwIwAg&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DmlojNcvoW68&ei=RoX4U8zwLdbvaKmOgMgH&usg=AFQjCNE5rRlHfVw-n_jgZAXEhK-Q1dd_Mg&sig2=mt8454k4FzqoVBprIqorNg&bvm=bv.73612305,d.d2s
<RelativeLayout //Change this to a linear layout
android:id="#+id/imagelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2" > //add this to linear layout attribute
<ImageView
android:id="#+id/r"
android:layout_width="0dp" //change width to 0dp (in case of horzontal layout)
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="3dp"
android:background="#drawable/back"
android:layour_weight = "1"/> //add this to both view
<TextView
android:id="#+id/resulttext"
android:layout_width="0dp" //change width to 0dp (in case of horzontal layout)
android:layout_height="wrap_content"
android:textSize="30sp"
android:textStyle="bold"
android:text="Hello"
android:layout_alignLeft="#id/r"
android:layout_alignTop="#id/r"
android:layout_alignRight="#id/r"
android:layout_alignBottom="#id/r"
android:layour_weight = "1"/> //add this to both view/>
</RelativeLayout> //This again has to be linear layout

Use LinearLayout instead/inside RelativeLayout and set the weight property to 0.5 in each child view. you should also use layout:gravity to set the child view on the top.

Try this:
private int columnWidth;
//get Screen Size
public int getScreenWidth() {
int columnWidth ;
WindowManager wm = (WindowManager) this
.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
final Point point = new Point();
try {
display.getSize(point);
} catch (java.lang.NoSuchMethodError ignore) { // Older device
point.x = display.getWidth();
point.y = display.getHeight();
}
columnWidth = point.x;
return columnWidth;
}
//set height and width of Imageview
int height=columnWidth;
int width=columnWidth;
img.setLayoutParams(new RelativeLayout.LayoutParams(height,width));
Hope this may help you

Related

Fill the screen with 2 RadioButtons?

How to fill a ConstraintLayout with two radioButtons inside of a RadioGroup? I can't find a way to do it. I post here two images, one is how I want to make it look, and the other is how it looks right now with my code.
This is how it looks right now
This is how I want
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/constraintLayout6">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="#+id/radioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/radio_selector"
android:button="#color/transparent"
android:elevation="4dp"
android:padding="16dp"
android:text="Paypal"
android:textAlignment="center" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/radio_selector"
android:button="#color/transparent"
android:elevation="4dp"
android:padding="16dp"
android:text="Contrarreembolso"
android:textAlignment="center" />
</RadioGroup>
</androidx.constraintlayout.widget.ConstraintLayout>
The best thing that I could do after reading some answers on StackOverflow and trying many things is to get to this point:
I have taken this layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".MainActivity">
<RadioGroup
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="#+id/radioButton"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:background="#193312"
android:elevation="4dp"
android:text="Paypal"
android:textAlignment="center" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#122B33"
android:elevation="4dp"
android:gravity="center"
android:text="Contrarreembolso"
android:textAlignment="center" />
</RadioGroup>
</androidx.constraintlayout.widget.ConstraintLayout>
And used this code to get the height of the screen and put half of it on my views, inside your activity:
#Override
protected void onStart() {
super.onStart();
//Get the height is the screen
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int height = size.y;
DisplayMetrics displayMetrics = new DisplayMetrics();
RadioButton radioButton1 = findViewById(R.id.radioButton);
RadioButton radioButton2 = findViewById(R.id.radioButton2);
//Give view half of the screen height
ViewGroup.LayoutParams params = radioButton1.getLayoutParams();
params.height = (height)/2;
ViewGroup.LayoutParams params2 = radioButton2.getLayoutParams();
params2.height = (height)/2;
}
Notice that this layout is not perfect looking, your radio buttons do spread across your device in height but they are not equal, the one thing left to do if you want your button to be equal in height is to calculate the action bar height and take it into account.

Android TextView with Marquee and layout_weight not scrolling

I have a dialog popping up with a title and a close button. This is the XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:id="#+id/text_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="24dp"
android:layout_marginRight="0dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:maxLines="1"
<!--- android:singleLine="true" <-- Do not comment about this, it is deprecated --->
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:textSize="20sp"
android:textColor="#android:color/black"
/>
<ImageView
android:id="#+id/backburger"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:src="#drawable/ic_close"
android:foreground="?android:attr/selectableItemBackground"
/>
</LinearLayout>
Like you can see the TextView has all the things it needs for a marquee, the singleLine options is deprecated, so I can't use it. I do call setSelected(true) in my Java. There are lots of questions about a marquee, but none with layout_weight and from '17.
This is the preview of the XML:
Try this one:
In your Xml:
<TextView
android:id="#+id/text_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textSize="20sp"
android:textColor="#android:color/black" />
and your Code:
tv = (TextView) this.findViewById(R.id.text_title);
tv.setSelected(true);
Hope its help:)
public void setticker(String text, TextView view) {
if (text != "") {
view.setText(text);
//view.setTextSize(25.0F);
Context context = view.getContext(); // gets the context of the view
// measures the unconstrained size of the view
// before it is drawn in the layout
view.measure(View.MeasureSpec.UNSPECIFIED,
View.MeasureSpec.UNSPECIFIED);
// takes the unconstrained width of the view
float width = view.getMeasuredWidth();
float height = view.getMeasuredHeight();
// gets the screen width
float screenWidth = ((Activity) context).getWindowManager()
.getDefaultDisplay().getWidth();
// view.setLayoutParams(new LinearLayout.LayoutParams((int) width,
// (int) height, 1f));
System.out.println("width and screenwidth are" + width + "/"
+ screenWidth + "///" + view.getMeasuredWidth());
// performs the calculation
float toXDelta = width - (screenWidth - 0);
// sets toXDelta to -300 if the text width is smaller that the
// screen size
if (toXDelta < 0) {
toXDelta = 0 - screenWidth;// -300;
} else {
toXDelta = 0 - screenWidth - toXDelta;// -300 - toXDelta;
}
// Animation parameters
Animation mAnimation = new TranslateAnimation(screenWidth,
toXDelta, 0, 0);
mAnimation.setDuration(15000);
mAnimation.setRepeatMode(Animation.RESTART);
mAnimation.setRepeatCount(Animation.INFINITE);
view.setAnimation(mAnimation);
//parent_layout.addView(view);
}
}

Android Custom Camera - Crop image inside Rectangle

I have a custom camera app which have a centered rectangle view, as you can see below:
When I take a picture I want to ignore everything outside the rectangle. The view hasn't any connection with the Camera Preview or SurfaceView in my XML view, as follows:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView
android:id="#+id/cameraview"
android:name="com.kut.camera.KutCameraFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<View android:id="#+id/viewTamanho"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="400px"
android:layout_marginTop="300px"
android:layout_marginStart="70px"
android:layout_marginEnd="70px"
android:background="#drawable/border" />
<RelativeLayout
android:id="#+id/rel_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="1"
android:background="#android:color/black"
android:orientation="vertical"
android:padding="10dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textViewReferan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Evidência"
android:textColor="#android:color/white"
android:textSize="16sp" />
<Button
android:id="#+id/button_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#android:color/transparent"
android:text="Sair"
android:textColor="#2799CF" />
</RelativeLayout>
<LinearLayout
android:id="#+id/progress_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" >
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/islem_value_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Carregando..." />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:alpha="0.9"
android:background="#android:color/black"
android:padding="10dp" >
<ImageView
android:id="#+id/imageView_foto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/camera" />
<ImageView
android:id="#+id/imageView_photo"
android:layout_width="80dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:padding="5dp"
android:scaleType="fitCenter"
android:src="#drawable/fotoicon" />
</RelativeLayout>
</RelativeLayout>
</FrameLayout>
Can somebody help me how to crop the image properly? I tried to create a new Bitmap based on my XML but obviously it didn't work, something like:
Camera.PictureCallback jpegCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
//.../
Bitmap imagemOriginal = BitmapFactory.decodeByteArray(data, 0, data.length);
Bitmap imagemCortada = Bitmap.createBitmap(imagemOriginal, 70, 400, imagemOriginal.getWidth() - 70,
imagemOriginal.getHeight() - 400);
//.../
}
I put those initial values for x and y, and tried to subtract (based on XML values from View referring to marginTop, Bottom, etc...) from width and Height but I hadn't success because I don't know how to match View coordinates with the image coordinates taken from Camera. Also, it seems for me Bitmap.createBitmap does limited crop, apparently I can't crop it to a rectangle directly.
To control cropping, you must control the picture size and the rectangle size.
It is very important to a) choose the picture size with same aspect ratio as the preview, and b) make sure that the preview is not distorted on the screen. If you prepare your app for a wide range of devices, both tasks are not trivial. To achieve the latter, you need to control both preview size and the SurfaceView size. I have explained this in more detail elsewhere.
To keep it simple, I suggest to ignore the tablets that may have natural Landscape orientation. On phones, the captured image will be "rotated" 90° even if you set camera orientation to portrait (which only effects preview). Don't expect setRotation() to fix this for you: by the book, it is allowed to simply set the EXIF flag for the captured image.
You set the margins for viewTamanho in px. This may not scale well on variety of screens. I suggest setting the dimensions of this view programmatically, as certain percent of the preview surface. You can use support library to define this in XML, but I am afraid this will not give you enough control.
With all this at hand, let's say that we have preview of 1280×720, picture of 2560×1440, our screen is 1280×800, and the rectangle is in the middle, 616×400 pixels (which is more or less the size scaled from your screenshot).
The actual preview size on screen will be probably 1000x562, padded on the right and left with black margins of 79px. Then the following code will produce the expected captured picture:
public void onPictureTaken(byte[] data, Camera camera) {
//.../
Bitmap imagemOriginal = BitmapFactory.decodeByteArray(data, 0, data.length); // 2560×1440
float scale = 1280/1000F;
int left = (int) scale*(imagemOriginal.getWidth()-400)/2;
int top = (int) scale*(imagemOriginal.getHeight()-616)/2;
int width = (int) scale*400;
int height = (int) scale*616;
Matrix rotationMatrix = new Matrix();
rotationMatrix.postRotate(90);
Bitmap imagemCortada = Bitmap.createBitmap(imagemOriginal, left, top, width, height, rotationMatrix, false);
//.../
}
Here i used this
implementation 'com.otaliastudios:cameraview:2.6.2'
library for getting bitmap image after taking picture.
Here is the code how i achieved this
public void croppingRectangle (Bitmap bitmap, CameraView mCameraView, FrameLayout rectangle) {
int cameraHeight = mCameraView.getHeight();
int cameraWidth = mCameraView.getWidth();
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int leftAndRightMarginsInPixels = Math.round(Math.round(getResources().getDimension(Your_dimens) * 2));`
here i did scaling, after taking picture
int left = (int) Math.round(((double)rectangle.getX()/(double)cameraWidth) * bitmap.getWidth();
int top = (int) Math.round(((double)rectangle.getY()/(double)cameraHeight) * bitmap.getHeight();
int width =
(int) (capturedWidth - Math.round(((double)leftAndRightMarginsInPixels / (double) displayMetrics.widthPixels) * bitmap.getWidth()));
int height = (int) Math.round(((double) rectangle.getHeight() / (double) displayMetrics.heightPixels) * bitmap.getHeight());
Matrix rotationMatrix = new Matrix();
rotationMatrix.postRotate(0);
Bitmap croppedImage = Bitmap.createBitmap(bitmap, left, top, width, height, rotationMatrix, false);
}
P.S : I have achieved 95% accuracy for top & bottom, 70% in getting width of a frame

Android custom dialog not fill the entire dialog layout

I build a custom dialog to pop up an image with close button like this:
As you can see the dialog is not fitting the dialog layout and there's this white borer on the top and on the right, so how can i get rid the white border thing and make my custom dialog fit?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:orientation="vertical" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<LinearLayout
android:id="#+id/linearMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="-50dp" >
<ImageView
android:id="#+id/imgMain"
android:layout_width="300dp"
android:layout_height="350dp"
android:gravity="center"
android:background="#drawable/eairh_dialog"
/>
<!---add your views here-->
</LinearLayout>
<ImageView
android:id="#+id/imgClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:clickable="true"
android:src="#drawable/close_button" />
</FrameLayout>
</LinearLayout>
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Use Above Code in your Dialog class to make Dialog TransParent
Remove margin Top and right on LinearLayout:
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
To make the Dialog bigger, you can set those parameters to MATCH_PARENT.
int screenWidth = 0, screenHeight = 0 ;
Display display = thid.getWindowManager().getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_DeviceDefault);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.cart_empty);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = screenWidth;
lp.height = screenHeight;
dialog.getWindow().setAttributes(lp);
dialog.show();

Android TranslateAnimation to Center

I need to apply a translation animation to an ImageView, this ImageView is positioned at certain place and i need to animate it to the center of the screen. Here is my translate xml code, but it doesn't animate the ImageView to the center.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="0%p"
android:fromYDelta="0%p"
android:toXDelta="50%p"
android:toYDelta="50%p" />
</set>
This is the XML where the ImageView is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/WelcomeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/welcome_background"
android:orientation="vertical" >
<ImageView
android:id="#+id/welcome_innovaLogo"
android:layout_width="300dp"
android:layout_height="150dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="1dp"
android:layout_marginTop="5dp"
android:contentDescription="#string/welcome_innovaLogoString"
android:scaleType="fitXY"
android:src="#drawable/innova_logo" >
</ImageView>
<TextView
android:id="#+id/welcome_innovaInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/welcome_innovaLogo"
android:layout_marginTop="20dp"
android:layout_toRightOf="#+id/welcome_innovaLogo"
android:text="#string/welcome_innovaInfoString"
android:textColor="#9acd32"
android:textStyle="bold" />
<TextView
android:id="#+id/welcome_innovaHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/welcome_innovaInfo"
android:layout_marginRight="20dp"
android:text="#string/welcome_innovaHeaderString"
android:textColor="#9acd32"
android:textSize="20sp"
android:textStyle="italic" />
<ListView
android:id="#+id/welcome_commandsListView"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="#+id/welcome_innovaLogo"
android:layout_marginTop="40dp"
android:cacheColorHint="#00000000" />
<LinearLayout
android:id="#+id/welcome_loadingLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="450dp"
android:orientation="horizontal"
android:visibility="invisible" >
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:layout_width="50dp"
android:layout_height="50dp"
android:indeterminateDrawable="#drawable/progress_large" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:gravity="center_vertical"
android:text="Loading Data..."
android:textColor="#color/green_color"
android:textSize="19sp" >
</TextView>
</LinearLayout>
<!--
<fragment
android:id="#+id/welcome_facebookFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/welcome_innovaLogo"
android:layout_marginLeft="20dp"
android:layout_marginTop="?android:attr/actionBarSize"
android:layout_toRightOf="#+id/welcome_commandsListView"
class="innovaEgypt.com.Welcome.FacebookFragment" >
</fragment>
-->
Have a look at this question. I gave a similar answer but the animation is not from an xml but from code. Hope it helps.
EDIT:
Your problem is that the animation doesn't take into account the image dimensions. The animation is centering the origin coordinate of your ImageView.
I still suggest my solution.
I tried the code in the answer that I linked and it works. Just copy this function:
private void moveViewToScreenCenter( View view )
{
RelativeLayout root = (RelativeLayout) findViewById( R.id.WelcomeLayout );
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics( dm );
int statusBarOffset = dm.heightPixels - root.getMeasuredHeight();
int originalPos[] = new int[2];
view.getLocationOnScreen( originalPos );
int xDest = dm.widthPixels/2;
xDest -= (view.getMeasuredWidth()/2);
int yDest = dm.heightPixels/2 - (view.getMeasuredHeight()/2) - statusBarOffset;
TranslateAnimation anim = new TranslateAnimation( 0, xDest - originalPos[0] , 0, yDest - originalPos[1] );
anim.setDuration(1000);
anim.setFillAfter( true );
view.startAnimation(anim);
}
and call it passing your view as the parameter:
ImageView img1 = (ImageView) findViewById( R.id.welcome_innovaLogo );
moveViewToScreenCenter(img1);
If your image still disappear, maybe is because it is behind your other widgets, like the ListView. If that is the case, reestructure your xml layout definig the ImageView at the end, just after the Listview (just cut and paste the ImageView).
For future updates...
Apply view property animation to move position of widget. Image view in this case
int layoutWidth = parentLayout.getWidth();
layoutWidth = ((int) layoutWidth / 2) - (imageView.getWidth()) ;
Log.d(TAG, " position - " + layoutWidth);
imageView.animate()
.translationX(-layoutWidth)
.translationY(0)
.setDuration(500)
.setInterpolator(new LinearInterpolator())
.start();
Try adding delay to this code.
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
moveViewToScreenCenter( view );
}
},
1000);

Categories

Resources