I'm developing a game hangman and it contains A to Z buttons in it everything works fine only problem i'm facing is with the grid view which contains letters from A to Z. When i'm installing the game in mobiles of different screen sizes the grid view consisting of letters are not aligned properly.For small screen mobiles it is enabling scroll automatically and for big screen mobiles it is showing above the bottom margin. I need the grid view to be in fixed position i.e., letters from A to Z should be shown in all types of screen sizes without providing a scroll.The screenshots are below http://tinypic.com/r/2q07otc/8 http://tinypic.com/r/1z1zcwm/8 and my xml code is Please help in solving this so that my assignment completes Thanks in Advance
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="240sp">
<GridView
android:id="#+id/letters"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:horizontalSpacing="5sp"
android:numColumns="9"
android:padding="5sp"
android:stretchMode="columnWidth"
android:verticalSpacing="5sp"
android:layout_marginBottom="5dp" />
</RelativeLayout>
You can try with this android:numColumns="auto_fit" and android:stretchMode.
Related
Context:
I have two AutoResizeTextViews inside a LinearLayout. I would like to have the first one about 1/3 of the size of the second one, and both as large as possible. Therefore I use layout_weight=1 and layout_weight=3 as can be seen in the XML code below.
Problem:
When I hide other TextViews in the View of the Fragment (stored as mView), using:
textView7.setVisibility(View.GONE);
(..many more to GONE..)
more space gets available for the LinearLayout, and so I expect the AutoResizeTextViews to grow. However the two AutoResizeTextViews do not grow, and seem to keep their canvas size. They are moved to align to the new 1/3 ratio of the LinearLayout, so there really is space inside the LinearLayout.
When the Activity and the View is restarted upon device reorientation (I do not retain the Fragment) they DO change as expected, apparently the canvas is redrawn correctly then. How can I make the AutoResizeTextView to be redrawn correctly without have to turn the device?
Already tried:
mView.forceLayout();
mView.refreshDrawableState();
mView.requestLayout();
mView.invalidate();
linearLayoutAutoFit.invalidate();
tvTimer.invalidate();
tvTimer.setTextsize(999);
is all not working, the Text is not adjusted to the new size.
XML code:
<LinearLayout
android:id="#+id/linearLayoutAutoFit"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/viewline2"
android:layout_below="#id/progressBar3"
android:layout_alignParentLeft="true"
>
<AutoResizeTextView
android:layout_weight="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/Ready"
android:id="#+id/textViewAction"
android:textSize="999sp"
android:textColor="#ADFF2F"
android:singleLine="true" />
<AutoResizeTextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/tvTimer"
android:textColor="#fff"
android:text="#string/init_time"
android:textSize="999sp"
android:visibility="visible"
android:singleLine="true" />
</LinearLayout>
instead :
android:layout_height="wrap_content"
type :
android:layout_height="0dp"
Although the answer by Kastriot was very close, and also part of the solution, I found the solution today by testing the values inside the AutoResizableTextView class with Log outputs. The mistake I made was that I also had
android:layout_width="wrap_content"
Because of that, upon layout change, the width of the AutoResizableTextView was not adjusted! As a consequence, the text could not grow in size. Therefore the setting for the width should be:
android:layout_width="fill_parent"
such that the width of the AutoResizableTextView is large enough to fit a larger text.
In my app, I want to have some activities that display a series of small images, I'm aiming for 3 per row in portrait and 5 in landscape, but I'm not rigid about those numbers.
The first problem is, I can't figure out a layout, or a configuration of a layout that will allow me to achieve this effect properly. I've tried TableLayout, FrameLayout and RelativeLayouts, but none of them make my images look nicely arranged in both orientations.
In this case the images are flags. I've tried creating 9 Patches out of the ones with symbols in the middle which I don't want to be distorted. Android Studio doesn't pick up that they are .9 files. But that is a separate issue.
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/iceland"
android:layout_weight="0.25"
android:scaleType="fitXY"
android:id="#+id/imageView"/>
I made a mockup of what I'm trying to achieve. I'd really really appreciate any tips you guys can offer. Thanks!
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridView1"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="50dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</GridView>
taken from this link should deliver an example, that could be useful to you.
Let me show you two links to demonstrate my point:
http://i.snag.gy/QP1i2.jpg (The ListView is 60 pixels)
http://i.snag.gy/DvXsL.jpg (The ListView is 61 pixels)
The whole file is done with an outer Vertical LinearLayout to provide weighted percentages (e.g. the ListView is 75%, the search part is 4%, so on and so forth) independent of device screen size. Within that outer LinearLayout I have a nested Layout (Linear or Relative) depending on my needs for the particular row.
It works beautifully, except for the last part. And it seems a lot of the items I try adding end up messing the formatting so I'm not sure if the problem is how I'm doing the ListView. Anyways, here's the relevant code:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:background="#null"
android:layout_weight="0.75"
android:paddingLeft="0dip" >
<ImageView
android:id="#+id/searchdivider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"
android:contentDescription="#string/desc"
android:src="#drawable/searchdivider" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/searchdivider" >
</ListView>
</RelativeLayout>
Thank you for your help!
EDIT: I should add that I don't want the height to be 60dp, obviously. I want it to fill_parent; however I picked the arbitrary value of 60 and 61 to figure out exactly what change makes the layout mess up.
2nd EDIT: I think I figured out the problem. It seems when I make the Theme AppCompat, it looks and acts fine. But when I make the Theme NoTitleBar (with or without fullscreen) then it acts all screwy. I haven't changed it in the manifest but rather the place in the graphical layout that lets you modify it for that one activity only.
Any suggestions?
android:gravity="left" on imageView and android:gravity="right" on the other listView
I am trying to display a text box using textView.I am adding some data in it during runtime. I just want it to display a box of size 23 lines.
Code am using is this.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/twittertext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadingEdge="vertical"
android:maxLines="23"
android:minLines="23"
android:background="#drawable/dropshadow"
android:scrollbars="vertical"
android:text="Getting data on your slow n/w..."
android:textColor="#ffffff"
/>
</ScrollView>
</LinearLayout>
Now when i see this in emulator it's coming perfectly (Android 2.2) but when i test the same code in a real device (Wildfire 2.2.1) the box is not coming for 23 lines. Rather it just show a 5 line box. Am able to scroll but looks like the
:minLine
is not working.
Please help me.
Ok. I dont have a answer for it. But this is how i solved, just in case someone else want it.
I have used the screen pixels and then calculated the pixels i need for the view. Then added the same as
android:layout_height
property and it worked for me.
I have a gridview with a button adapter based on this tutorial.
The problem: When sliding up or down, right or left on the gridview, button resize for some reason. e.g from 85*85 px it get's to 100+ on 100+ and when moving finger back it get's to default. I don't really know why this is happening, ive searched alot and didnt find anything. Am I only one who has this bug? I tested it on a real phone too - same.
I would change attributes of GridView and only restrict Button height and see how it behaves
<GridView
android:id="#+id/gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
/>