Design issue in Android Studio - android

Issue
In design background is fit.
In attributes background is set to fill_parent
In phone it has gap from both sides!
Any idea why I get padding in phone and how to remove it?

Solved by android:scaleType="fitXY"

Related

CardView still shows a shadowed border even with cardElevation set to 0dp?

I don't really have much hope for this widget (CardView). It is surely some kind of bug they made and to fix it we need to put some real effort in. If the cardBackgroundColor is not transparent, everything seems to look fine (there is not any border as well as the shadow, although it may be still a little visible but not very sensitive to your eyes).
Now if I set the cardBackgroundColor to transparent (#android:color/transparent) I can see the trace with shadow around the CardView.
I know using the CardView with this style (transparent background with no border and shadow) is a little strange, but the style may change by some settings, so it should be used at first.
Here is the code (mainly for the CardView which causes the undesired effect):
<!-- ra is namespace at http://schemas.android.com/apk/res-auto -->
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ra:cardElevation="0dp"
ra:cardBackgroundColor="#android:color/transparent"
>
Here is the screenshot showing what's wrong with this CardView:
The first image is what I want. The second one is what looking fine if the background is not transparent (white). The last one is the failed image showing some kind of bug as I mentioned.
I wonder if I may have to switch to using some other layout (and if any requirement to support shadow comes, I have to switch to using CardView, which spends my time changing the code, not very conveniently).
I had exactly the same problem, with the elevation showing despite having card_view:cardElevation="0dp" in the CardView layout when the background is transparent. This was when CardView was being used with RecyclerView.
What did solve the problem for me was adding card_view:cardMaxElevation="0dp" to the layout.

android.support.design.widget.FloatingActionButton implenetation of FAB reduces image size

So I have started migrating to the official support design library for an Android app of mine, replacing elements as I go. I just replaced an FAB (implemented as ImageButton) with official android.support.design.widget.FloatingActionButton. But the icon inside the button is smaller as compared to the one it was in ImageButton. What may have been a reason?
FloatingActionButton's implementation:
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon" />
Tried adding app:fabSize="normal but that didn't work, either.
This is how it looks after using FloatingActionButton:
And this is how it looked like while using it as a ImageButton:
Set scale type to android:scaleType="center"
Just a guess since you haven't provided any details at all. The design library's FloatingActionButton has padding calculations which will shrink the icon if it is too large, whereas your ImageButton probably just centers the icon with no scaling at all. I'm guessing that you would not observe this behavior if you were using a correctly sized 24dp icon, like the ones you get from: https://www.google.com/design/icons/.
You can use : app:maxImageSize="..dp" to change the size of your icon!

FAB - square on pre Lollipop and without shadow on Lollipop

It looks like FloatingActionButton is not working ether on Android 4.0 and Lollipop. As you can see on image below, on Android Lollipopo shadow is missing and on Android 4.1.1 it's square :/
Anyone faced this issue?
Library version:
compile 'com.android.support:design:22.2.0'
Code:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc_ic_clear_mtrl_alpha"/>
Thanks to #harism comment, simply setting app:borderWidth="0dp" resolve both issues.
Note: don't forget to add xmlns:app="http://schemas.android.com/apk/res-auto" to your root layout.
If the FAB still appears as square after setting borderWidth to 0dp, make sure that you aren't setting android:background in your XML or calling setBackgroundColor in code.
You should use android:backgroundTint (XML) or setSupportBackgroundTintList (code)
#Raghunandan, I have same problem on Lollipop also.
Finally I find that the root cause is a drawable named "fab_background" in my drawable folder.
The drawable is previously used for my own fab implementation.
Now I can see round fab after I rename this drawable.
Setting
app:borderWidth="0dp"
works. But if you are getting rendering issues in Android studio and have the Renderer set to Android M or 22, set it to 21
Seems to be a bug. A developer said "Fixed internally. Will be out soon.".

What's wrong with the ICS Holo Dialog theme?

I've come across a bit of a weird issue with activities using the Holo Dialog theme (#android:style/Theme.Holo.Dialog) in Ice Cream Sandwich.
It seems like they ignore their layouts and fill the entire screen instead of the layout width and height from their XML layouts. The same layouts are working as expecting in Honeycomb, but not on Ice Cream Sandwich.
Example:
The correct way (Honeycomb)
The incorrect way (Ice Cream Sandwich)
Both devices are running the exact same version of the application, and are using the exact same layout. Here's the layout in question:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="940dp"
android:layout_height="600dp"
android:layout_margin="10dp" >
<GridView
android:id="#+id/gridView1"
android:layout_width="940dp"
android:layout_height="600dp"
android:horizontalSpacing="10dp"
android:numColumns="3"
android:smoothScrollbar="true"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" >
</GridView>
</LinearLayout>
Any ideas to how this can be solved? A similar issue occurs on my ICS-based Galaxy Nexus, which completely ignore the match_parent tag for height and width. Is the dialog theme broken in ICS?
Update:
I've done some more testing, and it seems like 894dp of width or less will produce the "correct" look, but if I set the width to 895dp or more, it'll be the incorrect look. The emulator's acting the same way. This is extremely weird...
I don't think it is true that ICS discourages dialogs. Indeed, they have a whole page at Android Design. What is true is that DialogFragment (which is even provided in the Android Support library) is preferred over the legacy Dialog.
I corroborate your observation about the dialog popping to full-screen, but the behavior is device-dependent. On my Xoom tablet it happens at 915dp, not 895. On my Galaxy Nexus, it happens at 444dp. And on my Galaxy Tab 10.1, it does not happen at all.
If you dig into the source, you can see that there is a Dialog theme that is descended from Holo for smaller screens and from Holo.Dialog.FixedSize for larger ones. I would have expected this to be based on display size, not layout size, but perhaps I would be mistaken. I'll try to figure out what causes the jump.
I couldn't find an answer for this myself, so I eventually dropped the dialog theme and instead used a full-width standard theme layout. I think ICS discourages the use of dialogs, so maybe that's why it's changed.
All version of Android ignore the width/height of a Dialog themed layout xml.
To fix this, after calling:
setContentView(R.layout.contacts_preferences);
add a line:
getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
or WRAP_CONTENT for your needs.
Try swapping your LinearLayout for a RelativeLayout. That will do the trick :)
Somehow LinearLayouts always fills the screen when displayed in a dialog. RelativeLayouts don't.

dividers between TabWidgets

Is the android:divider attribute under the TabWidget working? I tried the Tab Layout tutorial from android just to test (http://developer.android.com/resources/tutorials/views/hello-tabwidget.html) and set the android:divider to some image (for now I used the android vertical scrollbar as the drawable to really emphasize if its getting picked up (copied it from frameworks), but when I ran it on the emulator, it doesn't appear to be working. According to the docs, the TabWidget does seem to support this attribute: "Drawable used to draw the divider between tabs."
Can anyone help? I am using a nine-patched drawable as my divider image drawable.
MB
It doesn't look like the divider attribute is available anymore for TabWidget. One way to add a custom divider is to set it programmatically:
mTabHost.getTabWidget().setDividerDrawable(R.drawable.divider_vertical_dark);
Make sure however, you call this before you set the content of the tabs. It would crash on me if I called it after.
I had the problem in ICS, where divider was visible. None of the solutions worked except for the following.
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:fadingEdge="none"
android:showDividers="none" >
</TabWidget>
Key line was android:showDividers="none"
I had this issue and solved it with the following code
tabHost1.getTabWidget().setDividerDrawable(R.drawable.example1);
if(Build.VERSION.SDK_INT >= 11)
tabHost1.getTabWidget().setShowDividers(TabWidget.SHOW_DIVIDER_MIDDLE);
For api levels below 11, it worked with the first line. For 11 and higher I included this to get this working. setShowDividers is added in linearlayout from api level 11. Hope this helps someone
Having the same issue myself. I only see the problem in Ice Cream Sandwich (ICS / 4.0.x). In android 1.6 - 2.3.4 there is no issue, dividers show up properly when setting a drawable in code, or in the xml layout.
I've tried just about everything I can think of to fix it but nothing works, including Josh's answer above :( though I have noticed that when setting any drawable as the divider, it will take up the space between tabs as if there was a drawable there, but it's just not visible.
Hopefully that gives someone else a hint as to what could be happening..?
I removed divider line from tabbar with use of below magical lines.
mTabHost.getTabWidget().setDividerDrawable(null);
OR
mTabHost.getTabWidget().setDividerDrawable(R.Color.transperant);

Categories

Resources