Hi guys I want to resize an Image background of a Style, I have an Image View that uses the style and shows the background image
Style:
<style name="Background">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">50dp</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">#drawable/img_background</item>
</style>
So I have the "img_background", and it's size it's about 1920*1080, I want to resize it pefectly so it fits all devices sizes, How can make it resize automatically depending on the screen sizes?, Beacuse It doesn't work
It doesn't show the image properly is way off and is not resized properly to fit the screen.
I have a LinearLayout that has the style and then the Image view inside it. It doesn't fit the 1920*1080 properly, for example in a 800*480 resolution it is cropped off and not neatly resized
<LinearLayout
style="#style/Background"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageView
android:contentDescription="#null"
android:layout_marginBottom="8dip"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dip"
android:layout_marginTop="8dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:paddingLeft="15dip"
android:src="#drawable/img_background"
/>
</LinearLayout>
Thanks
Change layout_width and layout_height your xml
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
Remove the style from the LinearLayout
Put this as your imageView:
<ImageView
android:contentDescription="#null"
android:layout_marginBottom="8dip"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dip"
android:layout_marginTop="8dip"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:clickable="false"
android:paddingLeft="15dip"
android:scaleType="centerInside"
android:src="#drawable/img_background" />
Related
I am setting style,color and size to textview , that is working
this is my code `
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txt_agent_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center"
android:textColor="#000"
android:textSize="14sp"
android:textStyle="italic"/>
Please check your parent layout is correct some times transparent layer or such things create visualise problem with colour
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txt_agent_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:gravity="center"
android:text="AppCompatTextView"
android:textColor="#FFFFFF"
android:textSize="114dp"
android:textStyle="italic" />
Use Dimension for setting up a text size ,always avoid hard coding
If you want to set same style for text-color,text-size and text-style than you can create something like
<style name="MyTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textSize">#dimen/abc_text_size_body_1_material</item>
<item name="textColor">?textColorPrimary</item>
<item name="textStyle">italic</item>
</style>
I have a list view with logos of supermarkets as images. Currently, they are not centered perfectly and are distorted. Please look at the
Here is my layout of row item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/highlight_selector">
<ImageView
style="#style/imgPriceStoreLogoSmall"
android:id="#+id/imgStoreLogo"
android:src="#drawable/panda_logo"
/>
<LinearLayout
android:id="#+id/layoutPriceInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/lblStoreName"
style="#style/lblRowProductName"
android:layout_marginTop="5dp"
android:textColor="#color/black"
android:textSize="24sp"
android:fontFamily="sans-serif-thin"
android:text="Store Full Name"/>
<TextView
android:id="#+id/lblPrice"
style="#style/lblRowOriginalPrice"
android:textSize="20sp"
android:textColor="#color/black"
android:layout_marginTop="5dp"
android:text="SAR 16.95"/>
</LinearLayout>
<ImageView style="#style/imgRowArrowIcon" />
</LinearLayout>
and my style
<style name="imgPriceStoreLogoSmall">
<item name="android:layout_width">80dp</item>
<item name="android:layout_height">80dp</item>
<item name="android:layout_gravity">start</item>
<item name="android:padding">5dp</item>
<item name="android:scaleType">fitXY</item>
<item name="android:contentDescription">#string/app_name</item>
<item name="android:src">#drawable/no_image</item>
</style>
I do not know the actual sizes of the logo images but want to resize to fit in imageview nicely. Any help is appreciated.
Thanks,
Noorul
The following code fits the image to yoursampleimage if the server image is so big
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/yousampleimagesizeimage" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:maxHeight="?android:attr/listPreferredItemHeight"
android:maxWidth="?android:attr/listPreferredItemHeight"
android:scaleType="centerCrop"
android:src="#drawable/serverorDynamicimage" />
</LinearLayout>
(or)
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:scaleType="centerCrop"
android:id="#+id/actualimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/sampleimage"
android:layout_alignLeft="#+id/sampleimage"
android:layout_alignRight="#+id/sampleimage"
android:layout_alignTop="#+id/sampleimage"
android:src="#drawable/actualimage" />
<ImageView
android:visibility="invisible"
android:id="#+id/sampleimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sampleactualimage" />
</RelativeLayout>
ImageView.ScaleType
use:
<item name="android:scaleType">centerCrop</item>
You have used width & height as 80dp. If image smaller that this height and width, it will be streached to fit in this area. If it is large, it will be scaled down to fit this area. I recommend using images multiple of 80x80 size e.g. 160x160, 40x40, etc.
layout_gravity = start means "Push object to the beginning of its container, not changing its size."
Whereas
center_vertical Place object in the vertical center of its container, not changing its size.
You can use "center_vertical" to put your image in vertically center.
I've the following problem. I've a TableLayout and two TableRows. Both TableRows contain two ImageButton. When a button is clicked I want to fade out other three buttons and translate the clicked button at the center of the screen. When it is translated the top or bottom half disappeared like it's hidden by the other table row. I've tried to set transparent background of table rows, to set alpha=0, to change layout and also I've tried to use ScaleAnimation, but the problem doesn't disappear. How can i show the disappeared half? I post also the layout code and a link to the screen with the problem.
http://it.tinypic.com/r/1zejhir/5
`
<RelativeLayout
android:id="#+id/l34"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_alignParentTop="true">
<ImageButton
android:id="#+id/four"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|right"
android:src="#drawable/unor"
android:alpha="0"
android:onClick="translate"
android:layout_alignParentLeft="true" />
<ImageButton
android:id="#+id/three"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|left"
android:src="#drawable/unor"
android:alpha="0"
android:onClick="translate"
android:layout_alignParentRight="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/l12"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<ImageButton
android:id="#+id/one"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|right"
android:src="#drawable/unor"
android:alpha="0"
android:onClick="translate"
android:layout_alignParentLeft="true" />
<ImageButton
android:id="#+id/two"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|left"
android:src="#drawable/unor"
android:alpha="0"
android:onClick="translate"
android:layout_alignParentRight="true" />
</RelativeLayout>
</RelativeLayout>
`
The problem is that you want to use "space" from other viewgroups, your view is bound to the hosting viewgroup (eg tablerow). It doesn't have anything to do with the transparent background. The solution would be to have one viewgroup holding all your icons. For example use a RelativeLayout.
make transparent
in java code-> imagebtn.setBackgroundColor(Color.TRANSPARENT);
xml-> android:background="#android:color/transparent"
create modify the styles.xml file resource in values folder, with following code
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
in manifest.xml file add the below step to which activity make you as transparent.
android:theme="#style/Theme.Transparent"
I've developed a game, which has boxes of textview with 1 letter within it.
in the emulator everything works fine, but, when i try to see it on my phone, the letter shifts down, and cuts the letter in the middle.
currently, my style is as so :
<style name="MoveLetter">
<item name="android:layout_width">#dimen/BoxSize</item>
<item name="android:layout_height">#dimen/BoxSize</item>
<item name="android:background">#drawable/blue_box_md_lighter</item>
<item name="android:contentDescription">#string/temp</item>
<item name="android:gravity">center</item>
<item name="android:scaleType">fitCenter</item>
<item name="android:textStyle">bold</item>
<item name="android:typeface">serif</item>
<item name="android:visibility">visible</item>
</style>
I use this style in my xml(partly) :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/game7_336letters"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/woodbackground1lighter_a_rotated"
android:orientation="vertical" >
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter1"
android:layout_marginLeft="180dp" android:layout_marginTop="30dp" android:textIsSelectable="true" />
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter2"
android:layout_marginLeft="240dp" android:layout_marginTop="30dp" android:textIsSelectable="true" />
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter3"
android:layout_marginLeft="300dp" android:layout_marginTop="30dp" android:textIsSelectable="true" />
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter4"
android:layout_marginLeft="180dp" android:layout_marginTop="175dp" android:textIsSelectable="true" />
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter5"
android:layout_marginLeft="240dp" android:layout_marginTop="175dp" android:textIsSelectable="true" />
<TextView style="#style/MoveLetter" android:id="#+id/game7_moveletter6"
android:layout_marginLeft="300dp" android:layout_marginTop="175dp" android:textIsSelectable="true" />
I've tried many options to add to the style - PaddingBottom,PaddingTop, layout_gravity = center, gravity = layout_horizontal, gravity = layout_vertical : all didn't help.
as far as right / left alignment - its good, the letter is in the center of the textview.
i'd appreciate any help you may have to offer..
Try specifying textSize, and make it smaller than your BoxSize dimen. Different letters have different dimensions, so it will be tricky to get right across different density devices.
incase anyone else has this issue : i figure out a way to pass the problem :
if you set the padding on code behaind, problem solved (for me at least..)
TextView tv = findViewById(...);
tv.setPadding( 0, -25,0,0);
I m not satisfied with the result of my layout whenever I test it in landscape mode on different screen size devices.
In portrait I like the margin of the textview. Since my current image size of the imageview will not fill the full width of some devices out there in landscape there is some whitespace left and right to it, which is fine.
however, the margin of the textview should also take this whitespace into account and add it somehow. I know i can create a different xml style for landscape modes, but any fixed margin wont help here... thanks for any help in advance
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:src="#drawable/start1_8" />
<TextView
style="#style/DescriptionTitle"
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView1"
android:text="Test Titelzeile" />
<style name="DescriptionTitle" parent="#android:style/TextAppearance">
<item name="android:textColor">#0099cc</item>
<item name="android:textStyle">bold|italic</item>
<item name="android:textSize">20sp</item>
<item name="android:layout_gravity">center_vertical|left</item>
<item name="android:gravity">top|left</item>
<item name="android:layout_marginLeft">15dp</item>
<item name="android:layout_marginRight">15dp</item>
<item name="android:layout_marginTop">5dp</item>
</style>
I would put it in a Relative Layout like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:src="#drawable/Untitled-1" />
<TextView
style="#style/DescriptionTitle"
android:id="#+id/textView1"
android:layout_alignLeft="#id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView1"
android:text="Test Titelzeile" />
</RelativeLayout>
Then it will be in the correct relative position regardless of view size or orientation.
resize the view in runtime and use(like screenwidth/4 ) a ratio hor image width and position.
use LayoutParams to do it.