widget centre

nico78

Active Member
Licensed User
Longtime User
widget centered

Hello,

how to create a widget that is positioned in the center of the display of the screen?

I understood the need to edit the xml file and put it in read-only, but when I change it no longer compiles because I errors.

In this example, what should I change?

B4X:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent">
  <AbsoluteLayout android:id="@+id/testwidget_panel1" android:layout_width="300dp" android:layout_height="300dp" android:layout_x="0dp" android:layout_y="0dp" android:visibility="visible">
    <AbsoluteLayout android:id="@+id/testwidget_panel2" android:layout_width="280dp" android:layout_height="280dp" android:layout_x="10dp" android:layout_y="10dp" android:visibility="visible" android:background="@drawable/testwidget_panel2_background">
      <ImageView android:src="@drawable/test" android:scaleType="fitXY" android:id="@+id/testwidget_imageview1" android:layout_width="260dp" android:layout_height="260dp" android:layout_x="10dp" android:layout_y="10dp" android:visibility="visible" />
    </AbsoluteLayout>
  </AbsoluteLayout>
</AbsoluteLayout>
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
You have to surround the second Absolutelayout with two LinearLayouts and modify the second Absolutelayout slightly:

B4X:
<AbsoluteLayout> [original from your example]
<LinearLayout android:id="@+id/base1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:layout_x="0dp" android:layout_y="0dp">
<LinearLayout android:id="@+id/base2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center" android:layout_gravity="center_vertical">
[The second AbsoluteLayout from your example with additional attribute android:layout_gravity="center_horizontal"]
[Rest of your Layout]
</LinearLayout>
</LinearLayout>
</AbsoluteLayout>

You have to make the layout file read only AND all other resources used in the layout file, too. In your example you have to make the testwidget_panel2_background.xml file and the "test.xml" file in the drawable folder read only, too.

Hopefully Erel will enhance the support for widget layouts in the future. Perhaps with a widget layout template file and support for other layout variants like landscape.
 
Upvote 0

nico78

Active Member
Licensed User
Longtime User
thank you for the explanation, it works! :sign0188:
 
Upvote 0

nico78

Active Member
Licensed User
Longtime User
I spoke too quickly, the image does not appear associated with ImageView?

I nevertheless put the image as read only!
 
Upvote 0
Top