optimizing screen from phone size to tablet size android development - java

I am fairly new to java and android. at the moment i am studying java at school. i just started working in this calculator just to get my hand in android developing. my problem at the moment is that when i deploy the app to the emulator (phone size 480x800) looks like Pic 001, but when i deploy it to my Kindle fire 1st gen (1024x600 i believe) looks like Pic 002. how can i make it so it look the same in every phone.
XML File

In order to have your buttons fill the entire width of your screen, put this in your tags Button:
android:layout_width="0dp" android:layout_weight="1"
instead of :
android:layout_width="80dp"
If you want the buttons to be higher :
- In your tags Button change android:layout_height="80dp" to android:layout_height="match_parent".
- In your tags LinearLayout which contain your buttons change android:layout_height="wrap_content" to android:layout_height="0dp" android:layout_weight="1".
- In your tag TextView change android:layout_height="wrap_content" to android:layout_height="0dp" android:layout_weight="X" where X is the value that gives you the right proportions.You will have a warning telling your that nested weight are bad for performance but it's the only way I know to do this.
In general, if you want a component to fill the empty space, set the width or height to 0dp and add a weight. The weight will define the proportions of the elements which want to fill the space.
I hope it will help you.

Related

Set visalbe border to matrix in XML

I have a matrix-like structure. Each row is a LinearLayout of n-TextViews. Both are created programmatically and added to a LinearLayout "container". In XML:
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
This is how it looks in App after building a matrix at runtime:
I always want to add a border to first/last column as well as to the first and second row, for each mxn-matrix. I want it to look like this:
I think the border / frame has to be added programmatically as well.
So my approach would be something like building a TableLayout as container and replace the LinearLayouts for each row with TableRows.
After that set the background color of TableLayout to black and give every needed TextView a padding on the right place programmatically.
But this seems to be a very stressful task. So I really hope there is a better way to do that.
I am using Kotlin.
I am very thankful for every suggestion!

How to put security patch on Text view?

I don't know what to say to this but I want mask or put patch on Text view.
See the picture below. I want effect like this. I've searched lot but didn't find any post with same requirement. How to achieve this?
You can pass two images in one TextView Like below Code:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/icon"
android:drawableRight="#drawable/pacth_icon"
/>
use
android:drawableLeft
and
android:drawableRight
to set your images in TextView.And you can setText and background Image as well.

EditText auto suggestions are blank or non existing

I have a standard straight forward EditText, I want to show the dictionary suggestions on top of this EditText so I did this in the XML:
<EditText
android:id="#+id/messaging_messageEdit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:layout_weight="85"
android:background="#drawable/clanz_edit_text_holo_dark"
android:ems="10"
android:hint="Type your message here..."
android:singleLine="true"
android:inputType="textAutoComplete"
android:textColor="#dedede" >
</EditText>
I thought that the inputType parameter would take care of the auto dictionary view. On my phone (Nexus Android 5.1) the dictionary view appears but is blank. On a Genymotion emulator (Android 4.1.1) it does not display at all.
What am I missing?
This can be one solutions if you are looking for AutoComplete TextView.
<AutoCompleteTextView
android:id="#+id/from_station"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/enter_start"
android:imeOptions="actionNext"
android:inputType="textNoSuggestions"
android:textColorHint="#color/transparent_black" />
You can also set threshold value using paramters.
Need to set adapter values at runtime.
If I understand correctly you want the keyboard to have auto correction right?
According to the Android developers website:
Can be combined with text and its variations to specify that this
field will be doing its own auto-completion and talking with the input
method appropriately. Corresponds to TYPE_TEXT_FLAG_AUTO_COMPLETE.
This is not what you're looking for. You are probably looking for textAutoCorrect which is this according to the Android developers website:
Can be combined with text and its variations to request
auto-correction of text being input. Corresponds to
TYPE_TEXT_FLAG_AUTO_CORRECT.
I've made a lot of apps and never used one of those though. It just auto corrects if you have a normal EditText.
I had the same problem not getting keyboard suggestions on some of my EditText views. Please pay attention there is a difference between autoComplete text views and getting keyboard suggestions while typing! They happen in two different places, first one inside the AutoCompleteTextView the other one on top of your keyboard while typing.. (for example you type te => it suggests "tea teaspoon teapot" to make your life easier.)
To achieve that I had to turn off the input types that I was setting programmatically and when you do so, the default behavior is back and that means getting keyboard word suggestions:
// etFieldValue.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
I tried the following but I still did not get a keyboard suggestions:
etFieldValue.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
at the end I commented all the above and it worked just fine!
here I also found that someone else had the reverse problem meaning they wanted to disable this functionality and they suggested to use the code that I had commented! read here

Android - Creating a dynamic TextView

I am creating an Android game and have an issue with dynamic text with a TextView. Essentiall within my layout, I have a TextView, within a Relative Layout with enough space for several lines.
What I would like to do is add 5 lines within the TextView, with a functionality that once it is trying to write a 6th line it automatically overwrites line 1, therefore only ever showing a max of 5 lines of text.
Example of What I am after:
dynamic line 1
...
dynamic line 5
Please find below my xml code:
<RelativeLayout android:id="#+id/battleconsole"
android:layout_width="fill_parent"
android:layout_height="135dp"
android:gravity="center_horizontal"
android:layout_below="#+id/spacer1" >
<TextView
android:id="#+id/battle_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Console with information" />
</RelativeLayout>
This is the code that I am using to update the text within the TextView:
TextView update = (TextView)findViewById(R.id.battle_details);
update.setText("test console data going in here");
I am not sure if this is even possible using a TextView, if not is there any other way I can solve this issue?
Thanks in advance
Keep the 5 lines in a collection (array or list). When you set the text on the TextView, join the lines in the collection on "\n". Then just replace the item in the collection with the updated text.
Android has a join method in the TextUtils class, but I prefer the Guava library's Joiner class. Check it out: Google Guava

ListView checkboxes are over text, how to pad text and force checkbox standard color?

I have a listview checkboxes with text in a Linear Layout:
<CheckBox android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/nomeAPP" style="?listItem" />
But those checkboxes are over the text.
There's any way to pad the text a little to the right?
Also, I was testing with a AVD with 2.2 SDK. Just tested on my phone (also on 2.2), but looks like because of the phone theme (i have a cooked rom) the checkbox color is white (instead the standard grey). Is anyone way to force the checkbox color to the usual grey?
Try using the padding attribute i.e android:paddingRight to apply padding to text towards right.Please refer this link.

Categories

Resources