سؤال

I have simple component - InfoPanel extending LinearLayout with 3 another linear layouts inside. Each of that 3 linear layouts contains 2 textviews.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#F0F"
    android:orientation="horizontal"
    android:baselineAligned="false" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="0.3"
        android:background="@android:color/transparent"
        android:gravity="left|center_vertical" >

                 <TextView
                     android:layout_width="0dp"
                     android:layout_height="wrap_content"
                     android:layout_weight="0.5"
                     android:background="@android:color/transparent"
                     android:gravity="right|center_vertical"
                     android:text="@string/info_lineM" />

                 <TextView
                    android:id="@+id/info_lineM"
                     android:layout_width="0dp"
                     android:layout_height="wrap_content"
                     android:layout_weight="0.5"
                     android:background="@android:color/transparent"
                     android:gravity="left|center_vertical"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="0.4"
        android:gravity="center_horizontal|center_vertical"
                 android:background="@android:color/transparent">

                 <TextView
                     android:layout_width="0dp"
                     android:layout_height="wrap_content"
                     android:layout_weight="0.5"
                     android:background="@android:color/transparent"
                     android:gravity="right|center_vertical"
                     android:text="@string/info_lineC" />

                 <TextView
                    android:id="@+id/info_lineC"
                     android:layout_width="0dp"
                     android:layout_height="wrap_content"
                     android:layout_weight="0.5"
                     android:background="@android:color/transparent"
                     android:gravity="left|center_vertical" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="0.3"
        android:gravity="right|center_vertical"
                 android:background="@android:color/transparent">

                 <TextView
                     android:layout_width="0dp"
                     android:layout_height="wrap_content"
                     android:layout_weight="0.5"
                     android:background="@android:color/transparent"
                     android:gravity="right|center_vertical"
                     android:text="@string/info_lineG" />

                 <TextView
                    android:id="@+id/info_lineG"
                     android:layout_width="0dp"
                     android:layout_height="wrap_content"
                     android:layout_weight="0.5"
                     android:background="@android:color/transparent"
                     android:gravity="left|center_vertical" />
    </LinearLayout>
</LinearLayout>

Java class for this component is pretty simple:

public class InfoPanel extends LinearLayout{
public InfoPanel(Context ctx)
    {
        super(ctx);
        LayoutInflater.from(ctx).inflate(R.layout.info_panel, this);
    }

    public InfoPanel(Context ctx, AttributeSet attr)
    {
        super(ctx,attr);
        LayoutInflater.from(ctx).inflate(R.layout.info_panel, this);
    }
    @Override
    public void onFinishInflate()
    {
        super.onFinishInflate();
    }
}

the main XML where i use that component seems like:

<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <com.project.my.components.InfoPanel
        android:id="@+id/InfoPanel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</TableRow>

Problem is, that my component have width only something about 10% of width of screen. Right now i am trying to search some same problem (i found much of topics, but nothing worked for me) for more than 5hours..:/ I guess its something really small and stupid what i am missing. Thanks for all idea.

هل كانت مفيدة؟

المحلول

Thats good ,you find the solution of your problem,table row has default behaviour of using properties of first row in all rows.But deleting it solved your problem thats the key thing.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top