Align the element in the corner of a round wear-resistant device

I am trying to align an object in the corner of my round_layout for a round wear device. As you can see here:

enter image description here

The digital circle will be beyond borders.

I saw the media documentation for Android in google IO 2014, and some guy showed that there is a line of code to properly align the objects. I want the digital processor to be in the upper left corner, but not exit the screen.

Has anyone received an offer?

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 round-robin 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 using BoxInsetLayout, but still the output is as follows:

enter image description here

Although I used

 app:layout_box="top" 

TextView goes beyond the screen. What did I observe?

+6
source share
1 answer

According to the things shown on Google IO 2014, you should use BoxInsetLayout :
Watch this video <- about 6:04

You can see the use of BoxInsetLayout in the DelayedConfirmation sample code. Here is the contents of the 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 following values ​​for the application: layout_box: left|top|right|bottom or all . You can use all in your case, then all content will be stored inside the box on all sides. The effect for this layout is ignored when the application runs on a square clock.


EDIT:

I just checked the code you posted as “not working”:

 <?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 told you to use the all value in layout_box , but even with top it works the same way it should:

app:layout_box="top" : (top offset only)

enter image description here

app:layout_box="all" : (offset from either side)

enter image description here

+12
source

Source: https://habr.com/ru/post/972141/


All Articles