Make a bingo table in Android xml - android

I am trying to create a large square and inside the large square there will be 25 small squares.I am using a png image of the square with small 25 squares in it and using linear and linear horizontal to align the large text view inside the square. But when I change the device screen the text comes out of the boundary of the png image square.
Is there any solution for this?
This the square image i am using
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.nijinsha.bingomultiplayer.Game_Act"
android:background="#drawable/bkgd"
android:padding="5dp">
<ImageView
android:layout_width="330dp"
android:layout_height="340dp"
android:id="#+id/imageView"
android:src="#drawable/bgrid"
android:background="#drawable/gdbk"
android:scaleType="fitXY"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<LinearLayout
android:orientation="vertical"
android:layout_width="330dp"
android:layout_height="340dp"
android:layout_alignTop="#+id/imageView"
android:layout_alignLeft="#+id/imageView"
android:layout_alignStart="#+id/imageView">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="68.5dp"
android:weightSum="1">
<TextView
android:layout_width="62dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="02"
android:id="#+id/textView1"
android:gravity="center_vertical|center_horizontal"
android:textSize="50sp" />
<TextView
android:layout_width="62dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="05"
android:id="#+id/textView2"
android:gravity="center_vertical|center_horizontal"
android:textSize="50sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Edit
The problem is with devices which is not HD

The problem was with the width of the imageView. I changed the width to 300 and now no problem. The problem was imageView was at its maximum and could not be bigger on low pixel density devices.

Related

Image look pixelated in recyclerview

I am trying to make a simple recyclerview with image on left and text on right so i gave image width and height of 70dp both and i used png image 1000x1000 exported from illustrator using export for screens(android), but it's showing edgy tried with 512x512 same result also tried putting different resolution in ldpi,hdpi,mdpi,xhdp still same result
without the recyclerview the problem persist
Single row screenshot
Here's my xml code for single row
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="20dp">
<ImageView
android:id="#+id/img"
android:layout_width="70dp"
android:layout_height="70dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp">
<TextView
android:id="#+id/heading_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="start"/>
<TextView
android:id="#+id/sub_heading_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/heading_txt"
android:textStyle="normal"
android:textSize="12sp"
android:gravity="start"/>
</RelativeLayout>
</LinearLayout>

android layout leaving small gaps

So I have a image view and below a relative layout. The desired is to always have the users see the text views and buttons in the nested layout. And the image is a top image ( not a full screen background) but some how there is a small gap and the background of the image is bleed past the image view. I have tried different Image scale types and different layouts completely(frame, all linear,etc..)
http://imgur.com/a/n4aIq
and some code
https://gist.github.com/whatkai/92f66d2322957d86dd3fe28a9a5d03c0
FYI layout-weights left gaps too.
There is too many ways to do it.
Try this solution using LinearLayout (orientation: vertical):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/REFragment"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#color/accidentAssistanceColor">
<ImageView
android:id="#+id/SettingsImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/ers"
android:layout_weight="1"/>
<LinearLayout
android:background="#color/appStartERSBackground"
android:layout_centerHorizontal="true"
android:id="#+id/onView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/SettingsImage"
android:gravity="bottom|clip_vertical|center"
android:orientation="vertical">
<Button
android:gravity="bottom|end"
android:layout_centerHorizontal="true"
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/transparent"
android:text="Not Now"
android:textColor="#color/white"/>
<Button
android:id="#+id/button2"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/button"
android:text="approve"
android:textColor="#color/white"/>
<TextView
android:gravity="center_horizontal|center_vertical"
android:id="#+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/button2"
android:layout_gravity="center"
android:text="BLdfdsAH"
android:textColor="#color/white"/>
<TextView
android:gravity="center_horizontal|center_vertical"
android:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BLAH"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
And to answer you about how to scall your image i used android:scaleType fitXY to respect to ratio aspet.
If you desire to understand how every scallType works, see the following link:
https://robots.thoughtbot.com/android-imageview-scaletype-a-visual-guide
set view tag between your image and layout.
like this.
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#000000" />

Image in chat bubble having unwanted margins

I am having this simple layout for chat bubble.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bubble_layout_chat_parent"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bubble_layout_chat"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/message_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/primary_text_light"
android:layout_gravity="top"
android:textSize="16sp"/>
<TextView
android:id="#+id/message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#999"
android:textSize="10sp"
android:textStyle="italic"
android:textColorHint="#color/grey"
android:layout_gravity="bottom|end"/>
</LinearLayout>
However, when I set image it leaves unwanted margins above and below the image.
How can I remove margins and make the bubble to fit image?
(Note: What I observed is the margins appears only when image width is larger than height. For images having width much smaller than height no margins observed)
use android:scaleType="fitXY" for your imageview
Thanks for everyone's comments. Setting android:adjustViewBounds="true" to ImageView fixed my problem. So my working ImageView now looks like:
<ImageView
android:id="#+id/message_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"/>

Overlay Text on an Image in Android

I would like to know if there is a way to overlay text on an image in Android and cater for various different screen sizes? Currently I simply use the image as the background image to the layout and then I just use textview's over that.
The problem I have is that when the image is scaled on another device with a smaller or bigger screen, the position of this text changes and it looks different since the text does not scale the same way the image does on a different device, even though I use DP to position the textview's.
Is there some way to anchor these textview's to a certain point on the screen so that it looks more or less the same on different screen sizes?
Check this. this Xml will work well in any Device.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/yourimage"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />
<TextView
android:id="#+id/advrttext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Center Text in any Device"
android:textStyle="bold"
android:textSize="40sp"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="59dp" />
</RelativeLayout>
You can also use a relative layout and do something like this
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:background="#drawable/uninorsample"
android:id="#+id/imageView12"/>
<TextView
android:id="#+id/example_Txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example Text"
android:textSize="16sp"
android:gravity="bottom|center_horizontal"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="#+id/imageView12"
android:layout_alignRight="#+id/imageView12"
android:layout_alignEnd="#+id/imageView12"/>
</RelativeLayout>
You can set image as background in any widget or layout than set textview on that with appropriate dimension.i.e you can set shadow image in relative layout and set textview on it use property like centerinparent so it will always center of the parent in any DP.
Try this:-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/clock_number"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Hello World!" />
</RelativeLayout>
Use FrameLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Overlayed Text"
android:layout_gravity="center"/>
</FrameLayout>

Scaling ImageView on bottom of Layout

I try to make a Layout with two TextViews on top and an ImageView on the bottom of the Layout. But I have problems with the scalingtyp of the ImageView. The Image should always resize propotional but be always on the center buttom. Here is a picture with my problem:
I hope you unterstand my problem.
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/transparent"
android:orientation="vertical" >
<TextView
android:id="#+id/textViewGameOver1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="top|center_horizontal"
android:gravity="center"
android:text="TextView1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textViewGameOver2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewGameOver1"
android:layout_centerHorizontal="true"
android:layout_gravity="top|center_horizontal"
android:gravity="center"
android:text="TextView2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageViewGameOver"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="#+id/textViewGameOver2"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom|center_horizontal"
android:scaleType="fitEnd"
android:src="#drawable/sheldon_win" />
</RelativeLayout>
Have anybody a idea to solve this problem?
Best regards!
You should be using a RelativeLayout instead of a LinearLayout. This will let you position the image where you want it and then you can set the size of the ImageView to be whatever size you want.
<ImageView
android:id="#+id/imageViewGameOver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/sheldon_win" />
This should put the image in the lower-right corner and the image should be whatever size the image file is. If you want to change that you can set the width and height to some size in dp's.

Categories

Resources