Why I can't display images in a large size, its results even smaller, is there something wrong with my XML code? or errors are in the java code? And i have "[Accessibility] Missing contentDescription attribute on image" on my XML code in ImageView
This my code :
Detail.xml
<ImageView
android:id="#+id/ivPosterImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:maxHeight="300dp"
android:src="#drawable/large_movie_poster" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ivPosterImage"
android:layout_marginTop="10dp" android:id="#+id/scrollView1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
Activity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_box_office_detail);
// Fetch views
ivPosterImage = (ImageView) findViewById(R.id.ivPosterImage);
....
Picasso.with(this).load(movie.getLargePosterUrl()).
placeholder(R.drawable.large_movie_poster).
into(ivPosterImage);
Please help me ...
Its clearly looking that your downloaded image have very small height and width dimension and you have settled the dimension around wrap_content. That's why you are getting this small icon instead of full image.
And again image download libs always use image attribute setSource in their code, which also set image around wrap_content.
Now you have 2 choice to show image wider:
set width = match parent,
height = fixed(any value as per your choice like 100 dp ,200 etc), i have not fixed the width because thats goona create exception on small or large screns.
set image background instead of image src that is by default set by image download libs.
Hopefully this will resolve your issue.
Related
I have two Buttons nested in a LinearLayout. Between these Buttons are two TextViews. In the Xml, I have set the foreground to an image for each of these Buttons.
It runs fine on my device for Api 23. But on other devices below Api 23, the foreground image does not display and instead results in a default white solid color. Is there any way to make these images show using foreground below Api 23?
We have tried FrameLayout but it does not do what we want it to do. Would ImageButtons be a better way to solve this issue?
One of the core functions of our app is that every time a user taps a Button, the size increases and the image stretches accordingly. This is done dynamically in code. If I were to use ImageButtons, I would need to set the layout parameters every time for height and width, rather than one line of code that sets the height.
Any tips would be appreciated!
EDIT: Code I am working with -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="11"
android:background="#android:color/black">
<Button
android:layout_weight="5"
android:id="#+id/firstP"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:foreground="#drawable/icebutton"
android:scaleX="1"
android:scaleY="1"/>
<TextView
android:layout_weight="0.5"
android:id="#+id/firstPlayer"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rotation="180"
android:textColor="#android:color/white"
android:background="#android:color/transparent"/>
<TextView
android:layout_weight="0.5"
android:id="#+id/secondPlayer"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:background="#android:color/transparent"/>
<Button
android:layout_weight="5"
android:id="#+id/secondP"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:foreground="#drawable/firebutton"
android:scaleX="1"
android:scaleY="1"/>
</LinearLayout>
We found out that there were two issues causing the images to not be shown.
1. The size of the image file was too big, creating an outOfMemory error which in turn resulted in the buttons not displaying the images.
2. The foreground attribute does not work for API 22 and below.
Steps to solving these issues:
1. We reduced the size of the image files.
2. We replaced Button with ImageButton
3. In the XML file we removed the foreground attribute, added a black background, and added the image via the src attribute. The following is a snippet.
<ImageButton
android:layout_weight="5"
android:id="#+id/firstP"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:src="#drawable/icebutton"
android:scaleType="fitXY"
android:background="#android:color/black"/>
We then had to change our code to dynamically adjust the height of the buttons to match the new image buttons with the help of this link by setting the LayoutParams:
how to change size of button dynamic in android
Now everything works perfectly!
I am absolutly new in Android development and I have a problem positioning image in the first app that I am developing.
So I have the following situation.
Into a layout file I have:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Dummy content. -->
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="0dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:src="#drawable/carbonara" />
<TextView android:id="#android:id/text1"
style="?android:textAppearanceLarge"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp" />
</LinearLayout>
</ScrollView>
So, as you can see, there is this ImageView element:
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:src="#drawable/carbonara" />
As you can see, for this ImageView I have setted the following values for the width and for the height
android:layout_width="wrap_content"
android:layout_height="300dp
This because I want that the image occupies horizontally all the space, but I have also to put a vaue for the height.
So for the previous value I obtain the following result:
As you can see in the previous screenshot there is a space up and down the image because I am manually giving a specific value to my ImageView element and this is wrong.
I have tryed to set a lower hwight value and this empty space is deleted for the android:layout_height="240dp" value.
But I think that this is not a good solution because it depens from the used screen.
So, what is the best way to handle this situation?
I have an image view that horizontally have to fill the screen and its height have be automatically handled and not manually specified with a dp value.
How can I implement this behavior? What am I missing?
Your problem can be solved with this simple line of code below
The XML attribute for this is:
android:scaleType="fitCenter"
Put it here like this your code below I just added new line see #1
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:scaleType="fitCenter" // #1
android:layout_height="300dp"
android:src="#drawable/carbonara" />
Also you are using src but you can use background attribute:
android:background="#drawable/carbonara"
Try to use android:scaleType="centerCrop" or android:scaleType="fitXY" if you need to rescale the picture
you can use screen aspect ratio for setting height and width to the image.Try following function.`
public void calculateAspectRatio() {
int imagewidth;
int imagewidth;
DisplayMetrics displaymetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
imagewidth=width;
imageHeight = (imageTwoWidth / 4) * 3;
}
set image height and width
imageview.requestLayout();
imageview.getLayoutParams().width = imagewith;//take value from above function for height and width.
imageview.getLayoutParams().height =imageheight;
`
im trying to set a bitmap to image something like:
android:src="img"
but only from code , and i get the img from the server.
but when im doing the setImageBitmap() method
it displays it like its in the background,like i would do this:
android:background="img"
so whatever isnt the image in the imageview becomes black and i dont want black background, this is the bad image i get:
Bad Image
and the image i want to get is:
Good Image
how can i set the image from bitmap in my code to be like src in xml ?
ty alot!
here is my xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:id="#+id/profile_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
app:civ_border_width="5dp"
app:civ_border_color="#c5eaf8"
android:elevation="10dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:layout_centerInParent="true"/>
<ProgressBar
android:id="#+id/progress_bar_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:visibility="gone"/>
</RelativeLayout>
my bitmap is working good with all the images except images like this one its filling their background with black..
The problem is that you're setting a transparent image and the background is filled black.
Check this answer to a similar question: https://stackoverflow.com/a/20402227/1281775
Another way is to create another ImageView below the current one with a desired background color.
The black portion you view in your image is transparent. Either change your image to non-transparent background or change the background color.
imageView.setBackgroundColor(color);
imageView.setImageBitmap(bitmap);
I have the following layout which displays an image and a text string:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center" >
<ImageView
android:id="#+id/ivIcon"
android:layout_width="#dimen/number_icon"
android:layout_height="#dimen/number_icon"
android:scaleType="fitXY"
android:layout_marginTop="#dimen/letter_icon_margin_top" />
<Button
android:id="#+id/btnNumber"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="3"
android:text=""
android:gravity="center"
android:textSize="#dimen/word_size_text"
android:textColor="#000000"
android:textStyle="bold"
android:background="#drawable/borderaction" />
</LinearLayout>
The ivIcon is displaying the images based on user input. It worked great when displaying one image per letter. But how do i fix the above layout so it displays the number of images based on user selection.
#dimen is used to change the view size based on the screen.
For example this is what is looking like when I use it for letter:
For the number, if the user chooses 5 the display should be:
If the user chooses 1 the display should be:
The code that is setting the image for the letter is:
ivLetterIcon = (ImageView) findViewById(R.id.ivIcon);
ivLetterIcon.setImageResource(R.drawable.apple);
How would I accomplish the number images?
Would it be best to have a blank layout without the images and add the ImageView at runtim depending on the number and have it centered? This way the images(s) are centered to the parent view layout?
Well I got an idea maybe you can try this out.
Try using GridView for displaying the number of apples by dynamically changing the column numbers and row numbers depending upon the screen.
For ex, if gridView is the GridView and the entered number is 11, you can do this.
gridView.setNumberOfColumns(5);
gridView.setNumberOfRows(3);
so 5x3 can accomodate 15 elements which can fit in 11 easily.
Then inflate the custom view containing the Apple into the columns.
Make the layout_height for the ImageView a fixed height
--edit--
int dp = TheFixedSize;
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
Imageview.setHeight(px);
So I'm loading images from a web service, but the size of the images are sometimes smaller or bigger than other images and the visualization looks silly when I put them in a ListView in android. I'd like to fix the size of my ImageView so that it only shows a portion of the image if it's larger than a preset amount. I've tried everything I can think of setting the setMaxWidth/setMaxHeight, setting the scale type to centerCrop, using ClipableDrawable wrapping my BitmapDrawable, setting using Drawable.setBounds(). I've tried setting in the XML and programmatically, but neither worked. I'm very surprised setting max width/height didn't do anything. Below is the XML I'm using ImageView definition in my layout file:
<ImageView android:id="#+id/recipeImage"
android:maxHeight="64px"
android:maxWidth="64px"
android:scaleType="centerCrop"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"/>
But,nothing has worked.
Just delete the maxHeight and maxWidth attributes and enter your units in layout_width and layout_height appropriately. But do not use the px unit - use dp instead, because these are device-independent.
This will fit the image in the specified height and width, irrespective of image size.
<ImageView
android:id="#+id/image5"
android:layout_width="300dp"
android:layout_height="200dp"
android:src="#drawable/image_1"
android:scaleType="fitXY"/>
Get ImageVIews as facebook posts.
Glide.with(context).load(link)
.placeholder(R.drawable.aboutlogo)
.fitCenter()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);`
<ImageView
android:id="#+id/img1"
android:src="#drawable/ic_menu_camera"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="center"/>