android-layout

How to put elements on top of each other in the same xml layout?

≯℡__Kan透↙ 提交于 2020-01-21 14:35:12
问题 How can I have more than one button, or a button and a text view in the same location in one layout but one on top of the other? I want to have a button that is hidden most of the time, but occasionally will have a non intrusive popup that will prompt something. The rest of the time there will be a text view there that is a different size. 回答1: Please take a look at RelativeLayouts. They use android:layout_below and android:layout_above to position elements below/above other elements. 回答2:

Google Maps in Android: Failed to find style 'mapViewStyle' in current theme

心不动则不痛 提交于 2020-01-21 10:56:26
问题 Sorry guys, another one about this topic. I have read ALL the postings about it so far, but so far none of the answers worked out for me. I have spent hours on trying to fix that now and before starting to pull my hairs out, I'd like to give it another try here. I'm getting the above error message in Eclipse when switching between XML layout and graphical layout. Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout,

Cards not shows in CardView

六月ゝ 毕业季﹏ 提交于 2020-01-21 10:12:30
问题 I have a simple CardView inside a RecyclerView but I can't see any cards appearing. Here's my current code: MainActivity.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:background="@color/colorPrimaryDark"> <include

Android Toolbar actionLayout of Switch causes text to jump when menu is pressed

我是研究僧i 提交于 2020-01-21 05:26:05
问题 Please refer to my project at: https://github.com/paulpv/ToolbarSwitch I am working on a simple custom layout for the Android Toolbar (aka: new ActionBar). This simple control adds a Switch to the Toolbar, and can be seen here highlighted in magenta: My problem is that immediately when the overflow menu is pressed, the Switch's Text jumps to the top of the Toolbar, and remains that way when you close the overflow menu: A similar thing happens in Landscape orientation (the subtle difference

how can I save a bitmap with onRetainNonConfigurationInstance() for screen orientation?

北战南征 提交于 2020-01-21 04:49:07
问题 In my class view phone cam will be opened and programme shows the bitmap after user take photo from phone cam but at the same time the user rotates the screen to "landscape" bitmap will disappear and activity's oncreate() will load again and then camera will be opened again. I didnt know save bitmap with onRetainNonConfigurationInstance() or onSaveInstanceState(). The question is this how can I save the bitmap(taken from phone cam) before user rotates the phone so that even if phone is

Android specifying pixel units (like sp, px, dp) without using XML

巧了我就是萌 提交于 2020-01-21 03:16:15
问题 Is it possible to specify the pixel unit in code. What I mean is, say I have a layout and I want the size to be 20dp, then is there any way to do so without writing in a layout xml 回答1: In a view: DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); float dp = 20f; float fpixels = metrics.density * dp; int pixels = (int) (fpixels + 0.5f); In an Activity, of course, you leave off the getContext() . To convert from scaled pixels ( sp ) to pixels, just use metrics

Android specifying pixel units (like sp, px, dp) without using XML

拥有回忆 提交于 2020-01-21 03:16:05
问题 Is it possible to specify the pixel unit in code. What I mean is, say I have a layout and I want the size to be 20dp, then is there any way to do so without writing in a layout xml 回答1: In a view: DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); float dp = 20f; float fpixels = metrics.density * dp; int pixels = (int) (fpixels + 0.5f); In an Activity, of course, you leave off the getContext() . To convert from scaled pixels ( sp ) to pixels, just use metrics

How to change activity on bottom navigation button click?

99封情书 提交于 2020-01-20 16:44:38
问题 I want to use bottom navigation bar in my existing android app but the problem is all screen are activity ,is it possible to load activity without hiding the bottom navigation bar. example: activity_main.xml <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support

how to get AttributeSet properties

寵の児 提交于 2020-01-20 14:23:10
问题 Suppose i have a class which extends ViewGroup public class MapView extends ViewGroup It is included in the layout map_controls.xml like this <com.xxx.map.MapView android:id="@+id/map" android:background="@drawable/address" android:layout_width="fill_parent" android:layout_height="fill_parent"> </com.xxx.map.MapView> How do i retrieve properties in the constructor from AttributeSet ? Let's say the drawable in the background field. public MapView(Context context, AttributeSet attrs) { } 回答1:

how to get AttributeSet properties

霸气de小男生 提交于 2020-01-20 14:23:09
问题 Suppose i have a class which extends ViewGroup public class MapView extends ViewGroup It is included in the layout map_controls.xml like this <com.xxx.map.MapView android:id="@+id/map" android:background="@drawable/address" android:layout_width="fill_parent" android:layout_height="fill_parent"> </com.xxx.map.MapView> How do i retrieve properties in the constructor from AttributeSet ? Let's say the drawable in the background field. public MapView(Context context, AttributeSet attrs) { } 回答1: