how to restrict image to show insider border - android

my screen not show image fit on border is goes out of border seeimage http://imgur.com/VMwFMzf is show tomoattow and cheexz image out of frame help me how do i fixed it?? i want to show first two images inside border like third image bread which correctly show inside border
holder.txtText = (TextView) convertView.findViewById(R.id.title2);
holder.imgThumb = (ImageView) convertView.findViewById(R.id.image2);
holder.txtText.setText(fifthscreen.Category_name.get(position));
imageLoader.DisplayImage(fifthscreen.Category_image.get(position),
activity, holder.imgThumb);
<com.schoollunchapp.HorizontalListView
android:id="#+id/listview2"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:layout_below="#+id/test_button_text5"
android:background="#ffffff"/>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/image2"
android:layout_width="90dp"
android:layout_height="100dp"
android:scaleType="centerCrop"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/imagebgborder"
android:src="#drawable/icon"
/>
<TextView
android:id="#+id/title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:padding="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:gravity="center_horizontal"
/>
</LinearLayout>
<!--imageborder.xml--->
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:left="2dp" android:top="2dp" android:right="2dp"
android:bottom="2dp"
/>
<corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
</shape>

Use this code
<ImageView
android:id="#+id/imageview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true" />
Then follow below points:
Set your image to Imageview as 'src' and not as 'background'.
Crop your image width and height related to your Frame height and width.

Related

Is there a way to achieve a glow effect on a Layout?

I need to do this effect on a layout like the following :
I tried with gradient on a shape, shadows, https://developer.android.com/reference/android/graphics/drawable/NinePatchDrawable , https://developer.android.com/reference/android/graphics/BlurMaskFilter
or even some libraries: https://github.com/SanojPunchihewa/GlowButton
But it always depends on a bitmap or on a button
What I have for the moment is my drawable and layout :
Shape drawable with strokes :
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="22.5dp"/>
<padding android:left="3dp" android:right="3dp" android:top="3dp" android:bottom="3dp"/>
<stroke android:color="#color/colorAccent" android:width="1dp"/>
<solid android:color="#android:color/transparent"/>
</shape>
Layout :
<LinearLayout
android:id="#+id/text_selections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:background="#drawable/btn_rounded_accent_light_stroke"
android:gravity="center"
android:layout_gravity="center"
android:orientation="horizontal"
android:tag="perso_button_rounded_accent_light">
<TextView
android:id="#+id/text_selections_line_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:tag="perso_text_view_accent"
android:text="Ma Commande"
android:layout_marginRight="5dp"
android:textColor="#color/colorAccent"
android:textSize="17sp" />
<Button
android:layout_width="25dp"
android:layout_height="25dp"
android:text="5"
android:textColor="#color/colorBlueLight"
android:background="#drawable/bg_rounded_button"
android:shadowRadius="90">
</Button>
</LinearLayout>
The library is rendering like following which is pixelating
Do you have an idea on how to do this effect ? (I want to do it programmatically, not using an image)
Thanks in advance

adding custom border drawable to android RelativeLayout not showing - Xamarin Forms

I'm trying to add a background rectangle shape to a custom RelativeLayout in android and I'm following the recommendations of most questions on here by implementing a custom drawable in customborder.xml and setting it as the background of the custom.axml view. I have also tried setting the relativeLayout source as well.
You can see I've also tried it in an imageView which isn't showing up either.
I've messed around with size and color but nothing appears to be rendered.
Am I missing something that needs to be done in code? Or the xml?
customborder.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
shape="rectangle">
<corners radius="20dp"/>
<padding left="50dp" right="50dp" top="50dp" bottom="50dp"/>
<stroke width="10dp" color="#B2F7FE"/>
<solid color="white"/>
</shape>
custom.axml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:background="#drawable/customborder">
<ImageView
android:id="#+id/imageViewBackground"
android:layout_width="fill_parent"
android:layout_height="49.0dp"
android:layout_gravity="center"
android:background="#ffededed"
android:adjustViewBounds="false"
android:alpha="1"
android:backgroundTint="#00000000"
android:foreground="#drawable/customborder" />
<refractored.controls.CircleImageView
android:id="#+id/Image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:src="#drawable/icon" />
<LinearLayout
android:id="#+id/Text"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="10dip"
android:layout_marginLeft="10.5dp"
android:background="#drawable/customborder">
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="24dip"
android:textColor="#FFFFFFFF"
android:paddingLeft="5dip"
android:text="Test"
android:layout_marginLeft="46.0dp"
android:layout_marginTop="12.0dp"
android:layout_gravity="left" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF7F3300"
android:textSize="20dip"
android:textStyle="italic" />
</LinearLayout>
Please replace your customborder.xml file with following code,
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
<padding
android:bottom="50dp"
android:left="50dp"
android:right="50dp"
android:top="50dp" />
<stroke android:width="10dp" android:color="#B2F7FE"/>
<solid android:color="#ffffff" />
</shape>
Your mistake was android prefix is missing.Also you are missing close tag in your layout.

Android Image Rounded Top

I woudl like to add an image with rounded top corners to my imageView but it doesn't appears rounded.
my shape_round_top.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#android:color/darker_gray"/>
<corners android:topRightRadius="10dp"
android:bottomRightRadius="0.1dp"
android:topLeftRadius="10dp"
android:bottomLeftRadius="0.1dp"/>
</shape>
my layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="250dp"
android:background="#drawable/grid_bg">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="200dp">
<ImageView
android:layout_width="200dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:id="#+id/image1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="5dp"
android:background="#drawable/shape_round_top"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp" />
</RelativeLayout>
</LinearLayout>
I set my image programmatically
int id;
id = context.getResources().getIdentifier("imagename", "drawable", context.getPackageName());
image.setImageResource(id);
Are you typing the correct drawable name android:background="#drawable/shape_round_top"or android:background="#drawable/shape"?
Except this, everything looks fine

Set checked/selected imagebutton in Android

I have a linear layout which contains three image buttons. Each image buttons has a different color. At the initial time, all image buttons are unchecked. I want to set checked/selected for an image button if the image button is selected (a blue V will overlap to the image button background ), and Another image button will be unchecked. How can I do it in android?
This is my layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="7dp"
android:layout_centerInParent="true">
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/color1"
android:background="#color/colorAccent"/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/color2"
android:layout_marginLeft="5dp"
android:background="#color/colorPrimaryDark" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/color3"
android:layout_marginLeft="5dp"
android:background="#color/colorPrimary"/>
</LinearLayout>
Updated: The blue V means checked status. It is similar the result
I would suggest to use checkboxes for this task.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="7dp"
android:layout_centerInParent="true">
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/color1"
android:button="#drawable/color_selector"
android:background="#color/accent"/>
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/color2"
android:button="#drawable/color_selector"
android:layout_marginLeft="5dp"
android:background="#color/primary"
android:checked="false" />
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="50dp"
android:layout_height="50dp"
android:button="#drawable/color_selector"
android:id="#+id/color3"
android:layout_marginLeft="5dp"
android:background="#color/primary_dark"/>
</LinearLayout>
and color_selector.xml should be placed into the drawable folder with the required selector (just an example)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="#drawable/ic_done_white_18dp">
<shape android:shape="rectangle" >
<stroke android:color="#color/white" android:width="2dp"/>
<corners
android:bottomLeftRadius="#dimen/spacing_xxsmall"
android:bottomRightRadius="#dimen/spacing_xxsmall"
android:topLeftRadius="#dimen/spacing_xxsmall"
android:topRightRadius="#dimen/spacing_xxsmall" />
</shape>
</item>
<item android:state_checked="false">
<shape android:shape="rectangle">
<stroke android:color="#color/white" android:width="1dp"/>
<corners
android:bottomLeftRadius="#dimen/spacing_xxsmall"
android:bottomRightRadius="#dimen/spacing_xxsmall"
android:topLeftRadius="#dimen/spacing_xxsmall"
android:topRightRadius="#dimen/spacing_xxsmall" />
</shape></item>
</selector>
Hope this will help.

state_pressed event is setting background on wrong button while click

I use Buttons inside Linear Layout, Table Row and Table Layout, maybe this has some influence.
The problem is that state_pressed doesn't work properly. When I'm pressing Button A/B/C/D, Android is selecting Button D (it is slightly darker).
You can see on the image, that shadow works properly, but the background is setting always on the wrong button D (bottom right corner).
After clicking any button I change its background programmatically and set backgrounds to red or green. It works properly.
The red button is selecting, because our opponent selects this answer. It's setting programmatically and don't have any influence for my bug.
Here is my layout code
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rozgrywka"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/icon2"
android:background="#ffffffff"
android:padding="5dp"
android:weightSum="1">
<TableRow
android:layout_width="fill_parent"
android:layout_weight="0.5">
<LinearLayout
android:id="#+id/first"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:id="#+id/buttonA"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_column="1"
android:layout_margin="5dp"
android:layout_weight=".5"
android:background="#drawable/rozgrywkabutton"
android:gravity="center_vertical|center_horizontal"
android:onClick="odpA"
android:text="A"
android:textAlignment="center"
android:textColor="#ff141414"
android:textSize="14dp" />
<Button
android:id="#+id/buttonC"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_column="2"
android:layout_margin="5dp"
android:layout_weight=".5"
android:background="#drawable/rozgrywkabutton"
android:gravity="center_vertical|center_horizontal"
android:onClick="odpC"
android:text="C"
android:textAlignment="center"
android:textColor="#ff141414"
android:textSize="14dp" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_weight="0.5">
<LinearLayout
android:layout_height="fill_parent"
android:layout_alignStart="#id/first"
android:layout_weight="1"
android:id="#+id/second">
<Button
android:id="#+id/buttonB"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_column="2"
android:layout_margin="5dp"
android:layout_weight=".5"
android:background="#drawable/rozgrywkabutton"
android:gravity="center_vertical|center_horizontal"
android:onClick="odpB"
android:text="B"
android:textAlignment="center"
android:textColor="#ff141414"
android:textSize="14dp" />
<Button
android:id="#+id/buttonD"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_column="1"
android:layout_margin="5dp"
android:layout_weight=".5"
android:background="#drawable/rozgrywkabutton"
android:gravity="center_vertical|center_horizontal"
android:onClick="odpD"
android:text="D"
android:textAlignment="center"
android:textColor="#ff141414"
android:textSize="14dp" />
</LinearLayout>
</TableRow>
</TableLayout>
drawable rozgrywkabutton.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<stroke android:width="1dip" android:color="#c7c7c7" />
<gradient android:angle="-90" android:startColor="#d3ced3" android:endColor="#b6b2b6" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<stroke android:width="1dip" android:color="#5e7974" />
<solid android:color="#58857e"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<stroke android:width="1dip" android:color="#c7c7c7" />
<gradient android:angle="-90" android:startColor="#e4e4e4" android:endColor="#cbc7cb" />
</shape>
</item>
</selector>
I was using static function to make button default.
public static void setBacground(Button buttonA, Drawable draw) {
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
buttonA.setBackgroundDrawable( draw);
} else {
buttonA.setBackground( draw);
}
}
and in my function which make my button look default
Drawable defualt = getResources().getDrawable(R.drawable.rozgrywkabutton);
Global.setBacground(ButtonA, defualt);
Global.setBacground(ButtonB, defualt);
Global.setBacground(ButtonC, defualt);
Global.setBacground(ButtonD, defualt);
when i change this to
Global.setBacground(ButtonA, getResources().getDrawable(R.drawable.rozgrywkabutton));
Global.setBacground(ButtonB, getResources().getDrawable(R.drawable.rozgrywkabutton));
Global.setBacground(ButtonC, getResources().getDrawable(R.drawable.rozgrywkabutton));
Global.setBacground(ButtonD, getResources().getDrawable(R.drawable.rozgrywkabutton));
everything start work properly. Thanks for your time.

Categories

Resources