Align element in corner of round Wear device - android

I am trying to align an Object into the corner of my round_layout for a round android wear device.
As you can see here:
The digitalclock will be out of bounds.
I've seen the android wear documentation at the google IO 2014, and some guy showed, that there's a line of code, in order to align the objects correctly.
I want the digitalclock to be in the top left corner, but not out of the screen.
Has anyone got a suggestion?
Here's the XML file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity"
tools:deviceIds="wear_round">
<DigitalClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/text"
android:textSize="20sp"/>
</RelativeLayout>
Edit:
My xml layout file looks like this right now, for the round activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1234567890"
app:layout_box="top"/>
</android.support.wearable.view.BoxInsetLayout>
As You can see, I tried to use the BoxInsetLayout, but still, the output is following:
Although I used
app:layout_box="top"
The TextView is out of the screen's bounds. What have I overseen?

According for things shown on Google IO 2014 you should use BoxInsetLayout:
Check out this video <- about 6:04
You can see the usage of BoxInsetLayout in DelayedConfirmation sample code. Here is a content of main_activity.xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/grey"
app:layout_box="top">
[...]
</LinearLayout>
</android.support.wearable.view.BoxInsetLayout>
You can set the app:layout_box to following values: left|top|right|bottom or all. You can use all in your case, then all content will be kept within the box on every side. The effect for this layout is ignored when app is running on square watch.
EDIT:
I've just tested the code you've posted as "doesn't work":
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1234567890"
app:layout_box="all"/>
</android.support.wearable.view.BoxInsetLayout>
With activity:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I've told you to use the all value in layout_box, but even with top it works as should:
app:layout_box="top": (only offset from top)
app:layout_box="all": (offset from any side)

Related

Change the quality of an ImageView

I'm trying to make a splash screen, I'm doing that with react native, but I'm using android studio to create the style.
First of all, I'm following this video that uses this library.
I have the following code of my splash screen:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#color/primary"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/launch_screen"
android:scaleType="centerCrop" />
</LinearLayout>
</RelativeLayout>
It looks like this:
As you can see, the quality of the logo is low, and I would like to make it better.
My drawable folder is the following:
Thanks!
It seems that your launch_screen.png file has a small resolution.
Change that file with bigger resolution with better quality.

Android Studio 2.3.1 design overwrites text xml

I am switching between text and design view in android studio and it seems that whenever I make a change in the text (xml) and the change back to design my changes are overwritten by something random. I want the text changes to take priority over the design tab.
For example:
I have this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.foo.MainActivity">
<RelativeLayout
android:layout_width="368dp"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp">
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
change it into this in text view:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.foo.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
when I switch to Design it somehow resets back to the first one. I want to see my changes even if they are wrong, without starting an emulator. I tried googling it but I can't see anybody else reporting this.

Video background on entire screen

I want to have a video background on my entire screen. Everything works correctly in java: it loops etc. The problem might be in xml.
Currently I have video on a top of the screen, it looks like this: (Video is perfeclty fitted in edges)
While my purpose is to have it entirely in my screen:
Please what should i make my xml look like to achieve my goal. Thanks.
XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<VideoView
android:id="#+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
First you need to set the orientation to landscape since you said you purpose is in landscape mode
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // add it below super.oncreate
If this code not working check out this link
or your could set the orientation in manifest just google it
And change this in your xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<VideoView
android:id="#+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
/>
</FrameLayout>

CalendarView horizontal lines disappear

I created an activity with a CalendarView. When scrolling up and down, sometimes one of the grey horizontal lines disappears. See the following image for the lines I am talking about. What causes this?
view_calendar.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<CalendarView
android:id="#+id/calendar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
ViewCalendar.java
public class ViewCalendar extends Activity {
#Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_calendar);
}
}
In your "calender" one of the disappeared grey line shows that you are in that row. In that disappeared line one block shows grey pointing to the current date. Like in your "calender" that block 22. You can see in the image provided in the below link.
http://www.edumobile.org/android/android-development/calenderview-example/
Try this code in your xml-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<CalendarView
android:id="#+id/calendar"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

Sony SmartWatch - show a view over the Gallery on the

While playing around with the Gallery I've got another question (this probably should be simpler).
I'm trying to show a view, lying in front of the Gallery, probably hiding it partially. Like a message dialog (Toast).
In order to do so, I'm using a FrameLayout with a Gallery in the back, and ImageView with a transparent src in the front. When a dialog should be shown, I'm setting the src to the needed drawable through "sendImage".
The problem is, as I assume, that the gallery/list items (that are added dynamically upon "onRequestListItem -> sendListItem") have more recent z-Order (as they have been added later), so the dialog is shown between the background of the Gallery and the transparent icons, representing the list items.
Maybe someone will have an idea, how to avoid this situation?
I am not aware of any way of adding views manually to the layout on the SmartWatch, or changing their zOrder through "bringToFront".
Here is the source code:
gallery.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Gallery
android:id="#+id/gallery"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/toast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/toast_dialog_message" />
</FrameLayout>
gallery_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20px"
android:src="#drawable/item_icon" />
</RelativeLayout>
GalleryControlExtension.java
sendImage(R.id.spritz_image, drawableResourceId);
P.S. In the emulator it works as expected: toast lies over the item_icon ...

Categories

Resources