I'm developing an app for 2.1 and above. First Activity in this app supports only portrait orientation, so I have android:screenOrientation="portrait" in AndroidManifest file. Activity looks good on almost all screen sizes and SDK versions, except WXGA screen and 4.0.3 SDK (also 3.2). On this screen, there were distortions of the background and buttons.
So I create a new empty Android project for 4.0.3 SDK. Add RelativeLayout and Button in the main.xml and android:screenOrientation="portrait" string in the AndroidManifest for main Activity. After debug (WXGA, 4.0.3) I got the same result.
If I change android:screenOrientation="portrait" to something else, the button looks good.
Same thing with Windows.
Why this happens? This is emulator problem?
I have a similar issue, and this occurs with various tablet emulators (eg. 3.0, 3.2, etc.) and only in portrait mode. It does not occur for the phone versions (eg. before Honeycomb). Below is the layout file I do a setContentView with resulting in distorted text in the lower right. It may seem trivial, however, it also distorts ImageViews, Buttons, etc. I also found as I place more views at the bottom of the screen, some of them get clipped, or buttons only partially highlight when pressed.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#888" >
<TextView
android:text="ABCDEF"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#FFF"
android:background="#000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right" />
</FrameLayout>
Related
app description :-
simple app with listView (orientation : horizontal)
the problem is :-
when i run the app on a real device , i found that all views direction get reversed
this is an item on android studio:-
app preview on android studio
but when it run on a real device it look like this
app on a real device
this is my layout (item.xml) code
<?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:id="#+id/item_layout_id"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mag_id"
android:layout_weight="1"
android:text="7.1"
android:textColor="#302f2f"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/country_id"
android:layout_weight="1"
android:text="Egypt"
android:textColor="#302f2f"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/date_id"
android:layout_weight="1"
android:text="July 21,2018"
android:textColor="#302f2f"
android:textSize="18sp"/>
</LinearLayout>
i want to display the same design from android studio preview on the real device
with the same view direction.
so what is the problem and how i can fix this.
This is due to difference between the screen size and display resolution, the layout that you're designing in the studio might look good on that exact screen size or resolution that you've selected in the layout editor, but that might not be the case for every device, your device in this case.
You can refer this thread for more detailed solution to your problem
you should check two or three things:
1- is your ListView parent layout has layoutDirection in XML?
2- have you called the method getWindow().setLayoutDirection(LayoutDirection.RTL) any where in your code?
3- if your list activity or fragment does not have number 2 then you should check your adapter class to see if there is any code written about ItemView direction.
4- if non of this is relevant for you please try changing preview android version and preview size.
hope this helps.
Android experience level: Novice.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="?android:attr/actionBarSize"
android:padding="10dp"
android:fillViewport="false">
I have applied top margin to the ScrollView which is the height of actionBar. That works well in two of my physical devices properly but not in one. Why the one device does not utilize the value?
Screenshots attached.
Lenovo A7000 with Marshmallow 6.0 Stock ROM:
Below the action bar, one or two lines are not visible. Probably behind the actionBar.
HTC phone and Samsung tablet: The text appears fine.
Try changing attribute value to ?attr/actionBarSize rather than using ?android:attr/actionBarSize
Hello stackoverflowers!
This is my button:
<Button
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.30"
android:text="#string/menu_button_newgame"
android:id="#+id/button_newgame"
/>
when I set it's alpha to 150 with
button_newgame.getBackground().setAlpha(150);
it starts looking weird on 2.2! On 2.3.3 the buttons look normally.
Android 2.3.3: (normal)
Android 2.2: (buggy)
What to do ?? :)
It seems to be a problem with the nine-patch.
Try to use
android:layout_height="wrap_content"
All the buttons has the same content and they should keep the same height.
Or try to create a custom nine-patch drawable to use as background.
am an upcoming android developer. I have my app in eclipse running on 2.2 android platform and the only thing remaining is adding fancy buttons to it. I have designed some buttons using photoshop but my main problem is to get the right dimensions (width, height and pixels) for my button so that they can fit properly on the screen. Please help! Thank you.
lucky for you, android sdk comes with a tool that allows you to adjust which parts of your image can be stretched, and which shouldn't be (as i'm thinking that's what you're worrying about). it's called 9-patch, and you can read about it here
What you have to do is play with your .xml file. You have to adjust your Buttons's properties like width and height and that will do.
Start playing with this for example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="50sp"
android:width="100sp"
android:background="#drawable/my_image"
android:text="I'm a button"
/>
</LinearLayout>
I recommend you this reading:
Android Button
My first (old) Android app (Suspension Calculator) is showing a problem I cannot find a solution for: the spinner control on some spinners is showing transparent lines in unwanted places. The pattern is this: every other spinner is having this problem, starting with the first spinner control. So while spinners 2, 4, 6, ... have no unwanted lines, spinners 1, 3, 5, ... have them.
The following image (link below) shows the spinner in selected state first, and in unselected state after the red separator. In selected state, the transparent line is at baseline height for the entire control except some places where the button text can be. It's a little different in unselected state.
I cannot provide an image directly:
[...] as a spam prevention mechanism, new
users aren't allowed to post images.
But I can give you a link:
Screenshot that illustrated the graphical spinner problem
The XML file under res/layout looks like this:
<ScrollView ...>
<TableLayout ...>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/units"
android:gravity="center_vertical"
android:paddingRight="5dp"
/>
<Spinner
android:id="#+id/unit_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
/>
</TableRow>
...
</TableLayout>
</ScrollView>
I see this problem at least since Froyo (Android 2.2). In earlier versions (at least Android 1.6), it wasn't there. It's not there in the Graphical Layout editor in Eclipse, but I see it running the application on the phone and in the emulator - that's at least consistent and hints to a problem I'm causing by not doing things right ;-).
Actually I can reproduce this behavior on Android 2.3. Not possible on Android 2.2 and lower.
It' doesn't matter if you place the Spinner in a TableLayout or RelativeLayout. Same problem there..
Only solution to get ride of the lines was to put a 1px-View between the spinner:
<Spinner android:layout_height="wrap_content" android:id="#+id/spinnerDriver"
android:layout_width="match_parent" android:layout_below="#id/driverDesc" />
<View android:id="#+id/helper" android:layout_height="1px"
android:layout_width="match_parent" android:layout_below="#id/spinnerDriver" />
<Spinner android:layout_height="wrap_content" android:id="#+id/spinnerDriver1"
android:layout_width="match_parent" android:layout_below="#id/helper" />
This is actually a very, very, very... ugly solution but it works for me...