Reputation: 3981
I have a layout file that I think looks ok, and it looks as I expect in the preview in android studio:
However, when I deploy on the phone, the entire layout is totally broken, and in addition, you can see that the image is flipped around! :
This is not anything I've seen before, and if someone could look at my layout and point out something I've done wrong that would be great. Am I using some non-supported layout types, or something else?
layout xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- Container for Top Banner and Content -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Top Banner - 25% -->
<LinearLayout
android:id="@+id/top_banner"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="@drawable/statuswidget_gradient_checked_in"
android:orientation="vertical"
android:gravity="center">
<!-- Logo -->
<ImageView
android:id="@+id/logo_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@drawable/wink"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:padding="15dp"/>
</LinearLayout>
<!-- Content - 75% -->
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:orientation="vertical"
android:gravity="center">
<!-- RelativeLayout for Text Alignment -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Status Text -->
<TextView
android:id="@+id/statusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BANANA"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true"
style="@style/widgetStatus" />
<!-- Location -->
<TextView
android:id="@+id/locationText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ORANGE"
android:layout_below="@id/statusText"
android:layout_marginTop="8dp"
android:layout_centerHorizontal="true"
style="@style/widgetLocation" />
<!-- Time -->
<TextView
android:id="@+id/time_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Today, 10:40"
android:layout_alignParentBottom="true"
android:layout_marginBottom="16dp"
android:layout_centerHorizontal="true"
style="@style/widgetTime" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Edit, provider:
private fun updateWidget(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int) {
val views = RemoteViews(context.packageName, R.layout.widget_userstatus)
views.setTextViewText(R.id.statusText, "BANANA")
views.setTextViewText(R.id.locationText, "ORANGE")
// Set up click handler to open the app
val intent = Intent(context, NubaMainTabActivity::class.java) // Replace with your target activity
val pendingIntent = PendingIntent.getActivity(
context,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
views.setOnClickPendingIntent(R.id.mywidget, pendingIntent)
// Push update to the widget
appWidgetManager.updateAppWidget(appWidgetId, views)
}
Upvotes: 0
Views: 52