brux
brux

Reputation: 3230

Android XML layout home screen widget

I am working with home screen widget.I want the button on the far right (second button) to stay fixed against the right of the parent linearlayout.

here is the code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="200dp"
android:layout_height="75dp"
android:background="@drawable/shape"
android:orientation="horizontal" >

<Button
    android:id="@+id/update"
    android:layout_width="30dp"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="Update"
    android:textSize="3pt" />

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:background="@drawable/shape"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/ssid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="SSID"
        android:textColor="#333333"
        android:textSize="5pt"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/wifiip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="IP address"
        android:textColor="#333333"
        android:textSize="5pt"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/extip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ssid"
        android:text="WAN IP"
        android:textColor="#333333"
        android:textSize="5pt"
        android:layout_weight="1" />
</LinearLayout>

<Button
    android:id="@+id/config"
    android:layout_width="30dp"
    android:layout_height="fill_parent"
    android:layout_alignParentRight="true"
    android:text="Config"
    android:textSize="3pt" />

the vertical linear layout in the middle is pushing or pulling the button right or left depding on the width of the textviews. Where am i going wrong?

Here is the xml for the widget provider

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android" 
android:minWidth="200dp"
android:minHeight="75dp"
android:initialLayout="@layout/widget"
android:updatePeriodMillis="180000"

 />

Upvotes: 0

Views: 835

Answers (1)

Srichand Yella
Srichand Yella

Reputation: 4246

Add this to your LinearLayout:

android:layout_width="0dip"
android:layout_weight="1"

That should do it. Let me know if that worked.

Edit:

Try this code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="200dp"
android:layout_height="75dp"
android:background="@drawable/shape"
android:orientation="horizontal" >

<Button
    android:id="@+id/update"
    android:layout_width="30dp"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="Update"
    android:textSize="3pt" />

<LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="0dip"
    android:layout_weight="1"
    android:layout_height="fill_parent"
    android:background="@drawable/shape"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/ssid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="SSID"
        android:textColor="#333333"
        android:textSize="5pt"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/wifiip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="IP address"
        android:textColor="#333333"
        android:textSize="5pt"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/extip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ssid"
        android:text="WAN IP"
        android:textColor="#333333"
        android:textSize="5pt"
        android:layout_weight="1" />
</LinearLayout>

<Button
    android:id="@+id/config"
    android:layout_width="30dp"
    android:layout_height="fill_parent"
    android:layout_alignParentRight="true"
    android:text="Config"
    android:textSize="3pt" />
</LinearLayout>

Upvotes: 3

Related Questions