When building layouts for Glass using Activity and Fragment it seems that some additional layout margins on top, left, right and bottom are present. Is there any way to reset that?
Do you also see these margins if you do screencast to yout mobile phone? In my case if i don't set any margin to the main layout of my activity, i can see some margin like you say, but if i do screencast to my mobile (with MyGlass app) I check that there isn't margin.
By convention there is a 40px margin round everything on a screen for glass, see the design guidelines or the developers site with example code
However you don't have to use them, by default the margins should be 0, so if you have a layout like:
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:src="#drawable/bg"
/>
</AbsoluteLayout>
It will show the image 'edge-to-edge' (640x350).
Of course with the screen on Glass it's hard to see where the actual edge is, so you really need to check a screen cast to check it's performing as expected.
Related
I am participating in the Udacity Android Basics degree. I am struggling with the project explained below. I am yet using only basic knowledge so please do not be surprised by the code simplicity. :)) I am eager to understand how to position elements so that they appear in every phone orientation mode using RelativeLayout.
You can find the XML here.
There are two screenshots of the app displayed in portrait and auto-rotate. The portrait looks alright but in auto-rotate half of the information displayed disappears.
My second question is related to the clickable elements. Once, I made them clickable they turned into red and underlined. Is this common or I should offset this with another statement?
This is my GitHub project.
Any help is appreciated.
Thanks,
Iva
For Your First Issue of Portrait and Landscape Try to put your view contents in a scrollview so that the screen contents will be scrollable when the height of the view is more than the screen height (In Portrait and Landscape Modes)
Sample with your code
<ScrollView
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="com.example.android.helloandroid.MainActivity"
android:background="#03B3E4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Add Your Contents Here ...
</LinearLayout>
</ScrollView>
For the Second question
Textviews with android:autoLink="" always takes the color from your colorAccent in styles.xml in your project if it has text that can be linked like website or mobile or map
you can change the text color by adding android:textColorLink="yourcolorhere"
to your textviews
Thanks
For auto-rotation, you can either lock rotation for your app locking screen rotation. You can use any of the methods suggested by other developers.
But If you want to add landscape orientation to your app, then you will have to define a separate XML layout file for it. You can do so by Creating a
layout-landdirectory by right clicking layout under res and putting the landscape version of your layout XML file in that directory. You can also refer to this answer for some help handle screen rotation without losing data in android
Coming to the second part of your question, if you make an element clickable, it is not supposed to turn red and underlined. I am not sure how you are making them clickable but to make an element perform a function on Click, just declare the element and define it. Then you can set an OnClick listener to it. You can see an example here making a button clickable. Youcan also try this code to make the button clickable:
Button btn= (Button) findViewById(R.id.button_main);
btn.setClickable(true);
I am trying to set a border for few of the image buttons for a particular screen layout in android. But for some buttons, I want to disable the border if the screen-layout background is blue colour. Please help me how to do this?
(I assume you design your app with Material Theme)
I think you can't do it (maybe possible with some hacky technique), because it's not intended to be that way.
Google has designed each view to underline each of their own purposes. So, I believe, If you can modify a button that way, it won't felt like a button to users thus can raise some misunderstanding.
What possibly user think if such button that doesn't have default blue, exist? Do they still think that as a Button?
Personally, I suggest that you leave the border as-is, if you still intended to make it feels like a Button.
Otherwise, if you really need it, you can always use CardView, put an ImageView inside it and attach OnClickListener to it. I think the result is quite similar because almost every rectangular view Google has nowadays, got similar visual to CardView.
Btw, I made this in my recent project to achieve a borderless Button-ey Image. Maybe it'll help.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardElevation="4dp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="0dp">
<ImageView
android:id="#+id/clickable_photo_thumbnail_image_view"
android:layout_width="#dimen/photo_thumbnail_size"
android:layout_height="#dimen/photo_thumbnail_size"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
</android.support.v7.widget.CardView>
(UPDATE) This is the screenshot from my app, produced with above code:
(In my screenshot, I already use a RecyclerView)
I need to put a vertical scroll bar in a home screen widget, and after searching many times, I can't find a convenient solution that works on API3 and above!
I tried many solutions:
- using bitmap created at run-time, but on some displays it never reach 100%
- a patch9 bitmap, but the scroll bar display gets completely messed up when the progress is near 0.
- using the addView() with 100 existing layout and it works great, except it's only available since API7!
- including all 100 layouts and showing only one at a time, work fine, but what a mess to include those in my 8 different widget layouts!
I tried to use the weight programmatically but it's not possible either, any other solution to resize a view based on a %?
Here is one progress bar layout I currently use:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:layout_weight="11" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ImageView android:src="#drawable/scale"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="89" />
</LinearLayout>
Only solution I found so far is to have all the possible progress levels ready to use in various Xml layout files.
On Android API < 7, all those need to be included in a single xml layout and shown/hidden at run-time, while on Android API >= 7, one can actually use addRemoteView() to include the desired layout in a much more efficient way!
You should use ScrollView! You must place this within a layout. By default, scrollview is for Vertical Scroll. If you want horizontal scroll you must specify HorizontalScrollView. Hope this helps
I am trying to set the orientation of the views underneath the GestureOverlay to none. At this point I am able to set the orientation to either vertical or horizontal. However, for my application I dont want either, this needs to be set to none.
In the article for gestures API, it says the following:
orientation: indicates the scroll
orientation of the views underneath.
In this case the list scrolls
vertically, which means that any
horizontal gestures (like
action_delete) can immediately be
recognized as a gesture. Gestures that
start with a vertical stroke must
contain at least one horizontal
component to be recognized. In other
words, a simple vertical line cannot
be recognized as a gesture since it
would conflict with the list's
scrolling.
And above that it shows this piece of code, displaying the android:orientation as vertical.
<android.gesture.GestureOverlayView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gestures"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gestureStrokeType="multiple"
android:eventsInterceptionEnabled="true"
android:orientation="vertical">
After searching online I found this piece of code for an Android Theme that uses android:orientation="none"
So I tried to implement this into my GestureOverlay, however when I use this it just produces this error in the XML file: error: Error: String types not allowed (at 'orientation' with value 'none'). My code is shown below:
<android.gesture.GestureOverlayView
android:id="#+id/gestures_alpha"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
android:gestureStrokeType="multiple"
android:fadeOffset="2000"
android:orientation="none"/>
Could someone let me know if there is a work around, or if this is a SDK version problem. I am coding using SDK version 7 (2.1.1).
Thanks
The android:orientation="none" option is part of the Replicant project and isn't valid for standard Android builds. In short, the only options you have are horizontal and vertical, sorry.
It looks to me like you're trying have both horizontal and vertical gestures being recognized using GestureOverlayView. This is the solution:
gestureOverlayView.setOrientation(GestureOverlayView.ORIENTATION_VERTICAL);
gestureOverlayView.setGestureStrokeAngleThreshold(90);
First of all, can I just say, I find laying out android UI's to be a frustrating experience? I used to think the XML layouts were simple and clean and awesome but every time I try to make anything with it I spend hours trying to do the simplest things!
In this particular instance I'm trying to make a simple horizontal bar that contains an image button of fixed size on the right and to the left of it I want an ImageView that takes up the rest of the available width. I see similar constructs all the time in the UI: the search box that appears at the top of the screen when searching, the text area and send button for composing text/googletalk messages, etc.
I've tried both a horizontal linear layout and a relative layout, and I can't get the button to look right in either one. My latest attempt has the following layout code:
It looks like this:
Using the hiearchyviewer indicates that both the imageview and the button have the same height (45px). And it shows the view dimensions and positions to be exactly what I'm looking for. Same height (differing widths of course since the ImageView is much wider). And they butt right up next to each other, centered in the Relative Layout. However the button as drawn on screen is obviously not taking up the full ImageButton view. I'm thinking it's something weird about the android system 9patch drawable used for the ImageButton background. But what do I know? I can't get it to look right no matter what I try.
How did you set up your RelativeLayout? Try to set it up like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:layout_width="wrap_content" android:src="#drawable/icon" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:id="#+id/imgButton"></ImageButton>
<ImageView android:id="#+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:src="#drawable/red_button" android:scaleType="fitXY" android:layout_alignBottom="#+id/imgButton" android:layout_alignTop="#+id/imgButton" android:layout_toLeftOf="#+id/imgButton"></ImageView>
</RelativeLayout>
Hope this helps.
If dimensions are exactly how you are looking for , then in ImageButton and ImageView , use android:scaleType="fitXY" and check.
For simple case , I might use linearlayout with horizontal orientation with two buttons in it with proper weights.