Android: Why is the zoom control like this? - android

Why does the zoom control show like this? It only happens on QVGA resolution smulator. It works perfectly on HVGA resolution.
This is the code that I used.
ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
public void onClick(View v) {
mc.zoomIn();
}
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
public void onClick(View v) {
mc.zoomOut();
}
});
zoomcontrols defined in xml as:
<ZoomControls android:id="#+id/zoomcontrols"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>

Shouldn't be nothing wrong with your code. It could be a emulator bug. You should test it on a real device if you can.
It seems you are not the only one. Zoom controls on emulator running Android 1.6 with QVGA

Related

Android widget button animation

In Android I have a widget with a button:
<Button
android:id="#+id/btnPlayPause"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/ic_button_play"/>
I want to apply a very basic animation to it when the user presses it.
Simple animation means: scale a bit down, and come back to original size.
Is this somehow achievable?
but.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
but.animate().scaleY(2f).setDuration(200).withEndAction(new Runnable() {
#Override
public void run() {
but.animate().scaleY(1f);
}
});
}
});

setTextDirection Programatically in api level 17

We are trying to set textDirection "rtl" programatically.
But, when we set it to "ltr" then on button click changing textDirection to "rtl" is not working.
Here is my code :
edtUSername.setTextDirection(View.TEXT_DIRECTION_LTR);
btnSubmit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
edtUSername.setTextDirection(View.TEXT_DIRECTION_RTL);
}
});
And this is not working only in api level 17.

Changing imagebutton image(from gallery) with longclick

I've searched the forums, but not have found any specific or understandable answers for my problem.
I'd like to change my Imagebutton image to a picture, selected from the gallery. Prefferrably the image should stay changed after closing the application.
My XML for the button is here:
<ImageButton
android:id="#+id/eat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:adjustViewBounds="true"
android:background="#drawable/eat"
android:clickable="true"
android:longClickable="true"
android:scaleType="fitCenter" />
The java code for playing the sound is here with the OnClick method.
ImageButton eat = (ImageButton) findViewById (R.id.eat);
eat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mp1.start();
}
});
I would like to add the OnLongClick method here too, (since to OnClick is allready taken and the image replacing should be a little different), but havent found the right way. Can You please guide me a little bit?
You need to return true from image's onLongClickListener.
Like this:
eat.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
//do something
return true;
}
});
eat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mp1.start();
}
});
This will not cause the image's onClickListener to be called as it means that the action has already been handled in longClickListener.

Change position of ZoomControls

I am working on a project related with Maps. The problem stands that the MapControls are positioned in right bottom. That position get covered with something else. So i want to remove the controls from there and place them somewhere else. I don't want to use custom positioning. Thanks in advance!
Create your own ZoomControls
<ZoomControls android:id="#+id/zoomcontrols"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
and you can set onclicklistener to that.
zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mapController.zoomIn();
}
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mapController.zoomOut();
}
});

Always show zoom controls on a MapView

Is there a way to always show the zoom controls on a MapView? I have added the zoom controls using
map=(MapView)findViewById(R.id.map);
map.setBuiltInZoomControls(true);
but the zoom controls fade in and out. I want them to always be visible.
Solved this by putting my own ZoomControls in my layout xml:
<ZoomControls android:id="#+id/zoomcontrols"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
and then setting up onClickListeners for then to handle the zoom:
zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mapController.zoomIn();
}
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mapController.zoomOut();
}
});
Intrications' solution does work, but you lose the built in functionality where the button disables when you have zoomed in or out all the way. You can retain this functionality by using the following instead:
localMapView.getZoomButtonsController().setAutoDismissed(false);
However, this does not let you place the controls wherer you want in the panel, and although it does not go away, it does not show up the first time until the user touches the screen once. I tried calling setVisible(true) on the controller, but that does not seem to work for some reason.

Categories

Resources