Why is the text on the right being cut out when there's still so much space remaining within the button? - android-layout

<Button
android:id="#+id/one"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_below="#id/space"
android:layout_weight="1"
android:onClick="one"
android:text="1"
android:layout_marginBottom="10dp"
android:layout_marginHorizontal="10dp"
android:textSize="70sp" />
I'm using the above code for the button but the right side of my text on the button is being cutoff despite there being so much space on the button. Am I missing out something?
I've learnt Java till grade 12 but learnt some basic XML for App Dev quite recently so I'm not aware of how to fix the issue. I tried looking for a solution but wasn't successful. If there is any additional info that needs to be mentioned, if I need to dig some more or if these kind of questions aren't entertained here, please let me know. Any help would be greatly appreciated.
Thanks!
This shows a screenshot of how the app. I decided to make (calculator) looks on my phone(moto G5).

Related

Android Studio 3.2.1 Resource not found error

I'd just started learning to write Android Studio apps so please pardon the noob question.
I'm using the book Android App Development for Dummies and trying to follow it to create the Silent Mode Toggle App.
In the book, it says that upon dragging an image into the src/main/res/drawable xxhdpi folder in AS (in AS 3.2.1, I believe should be src/main/res/mipmap-xxhdpi), "..., it regenerates the build/generated folder, and the R.java file is updated to include a reference to the two new images you added". However, mine doesn't seem to. And when I typed the "android:src="#" part, I don't see the resource "ringer_on" in the dropdown list.
(without the android:id & android:src line, there is no error)
I tried to clean project and rebuild but it shows me the below error:
Android resource linking failed
Output: C:\Users\xxx\AndroidStudioProjects\SilentModeToggle\app\src\main\res\layout\activity_main.xml:7: error: resource drawable/ringer_on (aka com.dummies.silentmodetoggle:drawable/drawable/ringer_on) not found.
error: failed linking file resources.
In the book, it says to create the silenttoggle app as a module within the helloworld project. So I tried to create the silenttoggle app as a new project and it's still the same error.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="#+id/phone_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/ringer_on"/>
</FrameLayout>
Also, I can't seem to find the r.java file anywhere.
My screen is as below:
enter image description here
Please help :( Thanks!
Your drawable is in mipmap folder and not drawable try #mipmap/ringer_on in place of "#drawable/ringer_on". change and it will work.

How to put space between switch button and its text in android?

I have the following element:
<Switch
android:text="Data about client?"
android:id="#+id/connected" />
But on designer the switch button and its text "Data about client?" are very glued together. I tried putting space between ? and " like that :
android:text="Data about client? "
But I don't like that type of solution very much
I had the same issue, but for me the accepted answer of Sravan Sriram did not solve the problem.
What worked for me was the tag
android:switchPadding = "10dp"
Minimum space between the switch and caption text. docs
Sure, kindly use this
android:switchPadding="5dp"
If you are using androidx.appcompat.widget.SwitchCompat then use app:switchPadding="8dp". This is work for me
Use tag "android:thumbTextPadding"

change layout_height by dp ,but it's not fix in different devices.why?

in my application i use a list view that i change its layout_height by dp . the problem is when i run my application on the emulator,the list view has a good view on the virtual machine. but when i run on my mobile (galaxy y ),it's not fix with my mobile.please help me.
here is my xml
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="335dp"
android:layout_margin="10dp"
android:cacheColorHint="#00000000"
android:background="#drawable/border_ui"
android:listSelector="#drawable/item_border_selected"
>
</ListView>
If you are giving height in dp then also it's height will remain device dependent.Instead,you should use wrapcontent or matchparent so that listview will look similar on different devices.

Android dashboard image size

Hello I am implementing a Dashboard to my application, where i want to overlay 4 images (one to top_right of parent, other to top_left, bottom_right and bottom_left). The reason why i want to overlay is because the images will fit together like a "puzzle".My question is, how can i set these images sizes to be a quarter of the screen,(having in mind multiple screens).
Thanks
You can take the help of RelativeLayot.it has control like
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"

List image with two columns android

Can anyone help me create an android layout like the image below.
It has two columns to store images.
Each image has the same width.
Thanks so much,
The easiest way would be to have two list views side by side and connect their onScroll() methods to scroll each other whenever one them is scrolled. (Don't forget to use a flag that you're scrolling programmatically, or you'll get StackOverflowError (kinda ironic, yeah :) due to infinite recursion). You can shift one of them by scrolling by half the images's height.
This is kind of a cheat though. Better way would be to make a custom layout derived from RelativeLayout that can store ids of last and second to last Views added to it. When next one is added, lay it out to be layout_below="#id/second_to_last", then the newly added View becomes last, the previous last - second to last and next time you'll be adding a view under it. (Yeah, i know, not exactly what you'd call a clear description :) but feel free to ask further questions)
Quick tip - remember about adding "android:adjustViewBounds="true"" in your xml-layout file for images. Without this, images have big margins on top and bottom.
Just tip, maybe you have problems with this.
Also remember about scaling functions in Android
look at pinterest like image gallery loader: https://github.com/etsy/AndroidStaggeredGrid
You could create a ScrollView that contains two columns (one vertical LinearLayout for each column). To populate it you simply create an ImageView object for each image and add it to the list by calling linearLayout1.addView(myImageView). PLease note that you might run into memory problems if you add a lot of images...
Your layout file would look something like this:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<!-- Left column -->
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="160dp"
android:layout_height="fill_parent"
android:orientation="verical" />
<!-- Right column -->
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="160dp"
android:layout_height="fill_parent"
android:orientation="verical" />
</LinearLayout>
</ScrollView>

Resources