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:
Related
picasso and glide are not loading the image from web. Below is the jave and xml. First i use picasso which is commented out now, then i use the glide library, but the problem is same. nothing appears on screen. if i ad image source from assets it appears on preview of android studio but i want to load image from web and show it in the image view. please correct my mistake if any..? Thanks.
JAVA:
ImageView imageBanner1 = (ImageView) findViewById(R.id.imageBanner1);
ImageView imageBanne2 = (ImageView) findViewById(R.id.imageBanner2);
Glide.with(getApplicationContext()).load("http://example.com/appBanner1.jpg")
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(imageBannerl);
/*Picasso.with(getApplicationContext())
.load("http://example.com/appBanner1.jpg")
.skipMemoryCache()
.into(imageBannerl);*/
imageBanner1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent inttv=new Intent(MainActivity.this,Play.class);
inttv.putExtra("url","http://example.com");
startActivity(inttv);
}
});
Glide.with(getApplicationContext()).load("http://example.com/appBanner2.jpg")
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(imageBanner2);
/*Picasso.with(getApplicationContext())
.load("http://example.com/appBanner2.jpg")
.skipMemoryCache()
.into(imageBanner2);*/
imageBannerAd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent imageBannerBrowserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com"));
startActivity(imageBannerBrowserIntent);
}
});
XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/tabHost"
android:layout_centerHorizontal="true"
android:id="#+id/imageBannerLayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageBanner1"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:background="#color/app_background" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageBanner2"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:background="#color/app_background" />
</LinearLayout>
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
Glide.with(this).load("url").into(imageView);
I think you need to check your ImageView variable name.
You have used ImageView imageBanner1 and ImageView imageBanne2 as variable name but never used it.Instead you have used imageBannerChannel and imageBannerAd as variable name. Once Check your code again. And make sure your url is fine.
I have a set of image views in a row,when the user clicks on the image, the background is getting changed.I want to add a transparent image on the top of my image view with a small tick in the middle to indicate that it is selected.
final ImageView iv_image=new ImageView(this);
LayoutParams iv_image_params=new LayoutParams(
Math.round(100*multiplier),
Math.round(100*multiplier));
iv_image_params.setMargins(5, 5, 10, 5);
iv_image.setId(Integer.parseInt(id));
try {
Bitmap bmp = BitmapFactory.decodeFile(DashBoard.file_path+image);
iv_image.setImageBitmap(bmp);
iv_image.setBackground(getResources().getDrawable(R.drawable.border_red_image_based));
iv_image.setSelected(false);
} catch (Exception e) {
}
iv_image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (iv_image.isSelected()==false) {
iv_image.setBackground(getResources().getDrawable(R.drawable.border_only_image_based));
iv_image.setSelected(true);
} else {
iv_image.setBackground(getResources().getDrawable(R.drawable.border_red_image_based));
iv_image.setSelected(false);
}
}
});
ll_view.addView(iv_image, iv_image_params);
*border_only_image_based: is my selector where I am just setting white border for an image view to indicate that it is selected.
normal image:
the image I want to be on the top of that image view:
Something like below should be helpful.
<RelativeLayout
android:id="#+id/rl_profile_pic_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp">
<ImageView
android:id="#+id/img_profile_pic_non_editable"
android:layout_width="110dp"
android:layout_height="120dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:background="#drawable/your_actual image"
android:scaleType="center" />
<ImageView
android:id="#+id/img_camera_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:src="#drawable/your_tick_icon"
android:visibility="gone" />
</RelativeLayout>
Where the first image view is your actual image. And second image is the tick mark you are going to place above it. Add a clicklistener to make tick mark visible or invisible. This code is based on my requirement. Please modify other properties as required.
Try to use tick mark image as icon size like 36x36,48x48,72x72,96x96
I am new to Android Programming, what I am trying to do in this Android Application is to create a xml page filled with buttons.
When I click the button, the button would change to light green color and when I click it again, it would change to light grey
The error: I am getting is when I click the button, it increases in size and overlaps with the other buttons, please help me out here, it is not user friendly in this case
attached below is the code:
lockerbooking.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/sisButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="28dp"
android:text="#string/sis"
/>
<Button
android:id="#+id/solButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/soeButton"
android:layout_alignBottom="#+id/soeButton"
android:layout_alignParentRight="true"
android:text="#string/sol" />
<Button
android:id="#+id/soeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/sisButton"
android:layout_alignBottom="#+id/sisButton"
android:layout_centerHorizontal="true"
android:text="#string/soe" />
</RelativeLayout>
Code:
makeBooking.java
public class makeBooking extends Activity {
Button sisButton;
Button solButton;
Button soeButton;
Button sobButton;
super.onCreate(savedInstanceState);
// Get the message from the intent
setContentView(R.layout.lockerbookpage);
Intent intent = getIntent();
// Initialize TextViews
sisButton = (Button) findViewById(R.id.sisButton);
solButton = (Button) findViewById(R.id.solButton);
soeButton = (Button) findViewById(R.id.soeButton);
sobButton = (Button) findViewById(R.id.sobButton);
}
public OnClickListener solButtonListener = new OnClickListener(){
boolean flag = true;
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(flag){
solButton.setBackgroundColor(Color.GREEN);
}
else{
solButton.setBackgroundColor(Color.LTGRAY);
}
flag=!flag;
}
};
...The code goes on
Please help me out here, I am eager to learn
to avoid overlapping of buttons, use fixed width and height for buttons:
change this:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
to some this like this:
android:layout_width="100dp" //what ever size suits your layout
android:layout_height="50dp" //fixing this,will not overlap the buttons
I am trying to change the image of an imagebutton using the following codes. Eclipse crashes but there is no error discoveredā¦ I've also used setBackgroundResource instead of setImageResource, but it didn't work. Nothing in Logcat, nither in errors. Please help me to find the right way.
I have two images for this imagebutton. - edit_on & edit_off
xml
Java
imageblockButton = (ImageButton)findViewById(R.id.buttonblock);
imageblockButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
imageblockButton.setImageResource(R.drawable.edit_on);
Intent intent1 = new Intent (context, ActivityBlockList.class);
startActivity(intent1);
v.setClickable(true);
}
});
my xml looks likeā¦
<ImageButton android:id="#+id/buttonblock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0sp"
android:scaleType="centerCrop"
android:background="#drawable/edit_off" />
In your xml
<ImageButton android:id="#+id/buttonblock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0sp"
android:scaleType="centerCrop"
android:src="#drawable/edit_off" />
use src instead of background
and
ImageButton btn = (ImageButton)findViewById(R.id.buttonblock);
btn.setImageResource(R.drawable.newimage);
Try this
imageblockButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.edit_on));
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 !