Zoom controls on an image placed in image view? - android

public class map extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageView iview = (ImageView)findViewById(R.id.iv1);
FrameLayout mContentView = (FrameLayout)
getWindow().getDecorView().findViewById(R.id.FrameLayout01);
final View zoom = iview.getZoomControls();
mContentView.addView(zoom, ZOOM_PARAMS);
zoom.setVisibility(View.VISIBLE);
} }
<FrameLayout
android:id="#+id/FrameLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:id="#+id/iv1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/delhi2"></ImageView>
<ZoomControls android:layout_height="wrap_content" android:id="#+id/ZoomControls01"
android:layout_width="wrap_content" android:layout_gravity="right">
</ZoomControls>
</FrameLayout>
Please help and give suggestion.its really important...
have image that i want to zoom. i have placed the image in an image view and was trying the java code given above but i having error regarding iview.getzoomcontrols(); that this function in undefined for image view...please help me in correction the code

it is because the method getZoomControls is defined for the ZoomButtonsController class.
http://developer.android.com/reference/android/widget/ZoomButtonsController.html
though, i don't know any tutorial. Good luck !

Related

How to display a map Frame above PanoramaGL-Activity

I use the PanoramaGL Library (https://code.google.com/p/panoramagl/) to display spheric 360° Images.
What I want:
The top half of the screen should contain a OSMdroid-Map (https://osmdroid.net/) and the bottom half shows panoramic images with PanoramaGL like this:
Problems:
You create panoramic Views in PanoramaGL using the class PLView which extends Activity.
If you show a panoramic image it always occupies the whole screen, and I see no way to change the layout. As soon as I try to define any xml-Layout, the panoramic image does not show up anymore.
My current code, where the map-part is commented out, so that only the panoramic image is displayed:
package com.example.campusnav;
//lots of imports...
public class MainActivity extends PLView {
private MapView mMapView;
private MapController mMapController;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*setContentView(R.layout.activity_main);
mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
mMapView.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
mMapController = (MapController) mMapView.getController();
mMapController.setZoom(13);
GeoPoint startPoint = new GeoPoint(52.432846, 8.369147);
mMapController.setCenter(startPoint);*/
PLSpherical2Panorama panorama = new PLSpherical2Panorama();
panorama.setImage(new PLImage(PLUtils.getBitmap(this, R.raw.p_1), false));
this.setPanorama(panorama);
}
}
Any suggestions how to work around this problem? Is there a way to display two seperate activities arranged in a vertical layout?
yes you can display both Panorama and map together
Extend your activity from PLView
XML
<RelativeLayout
android:id="#+id/rl_streetview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="#00FF40" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_mapview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_streetview"
android:layout_margin="0dp"
android:layout_weight="1" >
<fragment
android:id="#+id/location_map"
android:layout_width="match_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Activity
#Override
protected View onContentViewCreated(View contentView) {
ViewGroup mainView = (ViewGroup) this.getLayoutInflater().inflate(R.layout.activity_main, null);
rl_streetview = (RelativeLayout) mainView.findViewById(R.id.rl_streetview);
rl_mapview = (RelativeLayout) mainView.findViewById(R.id.rl_mapview);
}

In Android get center of Relative Layout on API 10

I'm trying to find the center coordinates of a RelativeLayout that for the moment, is empty. I need to find the center before I can put anything into the Relative Layout. The Relative Layout is not the whole screen, so I can't use metrics to find the screen dimensions. Since my minimum API is 10, I can't use rLayout.getX() or rLayout.getY(). So what I've tried is:
int xScreenInt = gBoard_RL.getWidth()/2;
int yScreenInt = gBoard_RL.getHeight()/2;
int xInt = gBoard_RL.getLeft() + xScreenInt;
int yInt = gBoard_RL.getTop() + yScreenInt;
and all I get is 0,0. Does anyone have an any ideas how I can get this done? Here's my layout and the Activity so far:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/gb1_root_RL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".GB1" >
<RelativeLayout
android:id="#+id/gb1_topInfo_RL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/blu_grade_bg"
android:orientation="vertical"
android:paddingBottom="15dp" >
<TextView
android:id="#+id/gb1_scValue_TV"
style="#style/mainScoreValueStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/gb1_score_TV"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/gb1_timeValue_TV"
style="#style/mainTimeValueStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/gb1_time_TV"
android:layout_marginRight="10dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/gb1_gf_RL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/gb1_topInfo_RL"
android:padding="10dp" >
</RelativeLayout>
the Relative Layout I need to find the center of is: android:id="#+id/gb1_gf_RL"
public class GB1 extends Activity {
TextView GScore_TV;
RelativeLayout gBoard_RL;
int xScreenInt, yScreenInt, xInt, yInt;
String xStr, yStr;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.cutin, R.anim.cutout);
setContentView(R.layout.gb_layout);
GScore_TV = (TextView) findViewById(R.id.G1_scoreValue_TV);
gBoard_RL = (RelativeLayout) findViewById(R.id.gb1_gf_RL);
gBoard_RL.setBackgroundColor(Color.MAGENTA);
xScreenInt = gBoard_RL.getWidth()/2;
yScreenInt = gBoard_RL.getHeight()/2;
xInt = gBoard_RL.getLeft() + xScreenInt;
yInt = gBoard_RL.getTop() + yScreenInt;
xStr = String.valueOf(xInt);
yStr = String.valueOf(yInt);
GScore_TV.setText(xStr + ", " + yStr);
}
}
Try putting your code in a onGlobalLayout listener:
myRelativelayout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
this.layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
//Your code here
}
});
EDIT:
Since, as #xorgate pointed out, the layout isnt drawn yet in the onCreate method. The onGlobalLayout method will be called when the layout is drawn and calculations such as yours should be done in there.
onCreate is called before a layout pass is done. All Views will have no size yet.
Try setting a global layout listener, and do the positioning code there.

androidplot: insert logo on graph

I would like to add a logo, or generally one or more bitmap,on androidplot graph.
I think the solution is to transform the androidplot graph as a bitmap and then add the other bitmap above.
But this solution is not good because convert the graph into bitmap i lose the quality of the graph.
The ideal would be not convert into bitmap. can someone help me?
thanks
Use FrameLayout for this purpose,
Add your graph xml code in FrameLayout and Add another ImageView or Button or what ever you like in FrameLayout
I am placing an ImageView in the bottom right corner of the Graph. You can change it.
XML Code:
<FrameLayout
android:id="#+id/frame_for_graph"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.androidplot.xy.XYPlot
android:id="#+id/mySimpleXYPlot"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
title="Stats" />
<ImageView
android:id="#+id/iv_Logo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginBottom="20dp"
android:layout_gravity="right|bottom"
android:src="#drawable/ic_launcher" />
</FrameLayout>
Java Code for Logo:
ImageView logo = (ImageView) findViewById(R.id.iv_Logo);
logo.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Logo Clicked",
Toast.LENGTH_LONG).show();
//Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("YOUR COMPANY URL"));
//startActivity(browserIntent);
}
});
SnapShot:

Drawing into scrollView

my problem I know is simple, but for the life of me I cant get an answer...
I have a LinearLayout that got a scrollview inside it... in the scroll view (in code) it should call a custom ScrollView to show on the application... it only shows black, nothing in it... here is my code
first the xml... simple LL with a textview, scrollview and button
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:layout_height="wrap_content"
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:text="test field" android:layout_alignParentTop="true"/>
<ScrollView android:layout_width="600dp"
android:layout_height="300dp"
android:id="#+id/v1"
android:fillViewport="true"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/gfx"
android:text="Gfx"
></Button>
</LinearLayout>
Now the onCreate of that activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
cw = getWindowManager().getDefaultDisplay().getWidth();
ch = getWindowManager().getDefaultDisplay().getHeight();
v = Draw2d findViewById(R.id.v1);
context = this;
setContentView(R.layout.gfx);
mDbHelper = new DbAdapter(this);
mDbHelper.open();
}
Draw2d is the class of the custom scrollView declared like so (it does have onDraw and everything. If I set the contentview to the Draw2d object directly it'll show no problem, but I need it withen a LL)
public static class Draw2d extends ScrollView{
public Draw2d(Context context) {
super(context);
}
Please any help is appreciated
Maybe because of you have nothing in the ScrollView? Try putting something in it. Check this link, you see there is another linear layout in the scrollview with "30px" layout height making the scrollview appear. If the layout_height was wrap_content, you would not see the scrollview if there is enough place on the screen for it.

How to use the xml setting in a view of a activity?

I want to show two views in one activity. If I clicked on button in the first view I want to see the second and other way round.
The views should not have the same size as the screen so I want e.g. to center it, like you see in first.xml.
But if I add the views with
addContentView(mFirstView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
the views are not centered. They are shown at top left.
How can I use the xml settings to e.g. center it?
first.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="#drawable/background"
android:layout_gravity="center"
android:minWidth="100dp"
android:minHeight="100dp"
android:paddingBottom="5dp"
>
<LinearLayout android:id="#+id/head"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton android:id="#+id/first_button"
android:src="#drawable/show_second"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null" />
</LinearLayout>
second.xml same as first.xml but with
<ImageButton android:id="#+id/second_button"
android:src="#drawable/show_first"
... />
ShowMe.java
public class ShowMe extends Activity {
View mFirstView = null;
View mSecondView = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initFirstLayout();
initSecondLayout();
showFirst();
}
private void initFirstLayout() {
LayoutInflater inflater = getLayoutInflater();
mFirstView = inflater.inflate(R.layout.first, null);
getWindow().addContentView(mFirstView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
ImageButton firstButton = (ImageButton)mMaxiView.findViewById(R.id.first_button);
firstButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ShowMe.this.showSecond();
}
});
}
private void initSecondLayout() {
// like initMaxiLayout()
}
private void showFirst() {
mSecondView.setVisibility(View.INVISIBLE);
mFirstView.setVisibility(View.VISIBLE);
}
private void showSecond() {
mFirstView.setVisibility(View.INVISIBLE);
mSecondView.setVisibility(View.VISIBLE);
}}
Hope someone can help.
Thanks
Why don't you use setContentView(R.layout.yourlayout)? I believe the new LayoutParams you're passing in addContentView() are overriding those you defined in xml.
Moreover, ViewGroup.LayoutParams lacks the layout gravity setting, so you would have to use the right one for the layout you're going to add the view to (I suspect it's a FrameLayout, you can check with Hierarchy Viewer). This is also a general rule to follow. When using methods that take layout resources as arguments this is automatic (they might ask for the intended parent).
With this consideration in mind, you could set your layout params with:
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(/* wrap wrap */);
lp.setGravity(Gravity.CENTER);
addContentView(mYourView, lp);
But I would recommend setContentView() if you have no particular needs.
EDIT
I mean that you create a layout like:
~~~/res/layout/main.xml~~~
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="....."
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
then in your onCreate() or init...Layout():
setContentView(R.layout.main);
FrameLayout mainLayout = (FrameLayout)findViewById(R.id.mainLayout);
// this version of inflate() will automatically attach the view to the
// specified viewgroup.
mFirstView = inflater.inflate(R.layout.first, mainLayout, true);
this will keep the layout params from xml, because it knows what kind it needs. See reference.

Categories

Resources