0

あげます。

TableLayoutクラスを拡張しようとしています(onMeasureをオーバーライドできるようにするため)。XMLで定義されたTableLayoutを拡張しています。

TableLayoutは表示されますが(カスタムの背景のために表示されます)、TableRowsは表示されません。

eclipseのXML「GraphicalLayout」でも、TableLayoutをカスタム拡張クラス(com.example.MainApplication.TableLayout_Schedrunning)に強制すると、ネストされたTableRowsは存在しません。

ただし、XMLをTableLayoutだけに変更すると、TableRowsが魔法のように表示されます。

<?xml version="1.0" encoding="utf-8"?>
<!-- this doesn't work-->
<com.example.MainApplication.Tablelayout_Schedrunning xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frmlay_schedule"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:padding="2dp"
android:background="@drawable/schedrunning_background" >
<TableRow 
    android:id="@+id/tblrow_header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="5dp"
    >
    <TextView 
        android:id="@+id/txtSchedRunningHeader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Schedule Running"
        android:textColor="@android:color/white"
        android:textSize="13dp"/>

    <TextView 
        android:id="@+id/txtCurrScheduleRunning"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:textSize="11dp"/>
</TableRow>

</com.example.MainApplication.Tablelayout_Schedrunning>

繰り返しになりますが、上記のカスタムクラスを単純なものに変更する<TableLayout>と、TableRowにネストされたTextViewが表示されます。私がそうしなければ、彼らはそうしません。私が見逃している簡単なことは何ですか?

ああ、TableLayoutはかなり標準的な拡張機能です。

public class Tablelayout_Schedrunning extends TableLayout {

public Tablelayout_Schedrunning(Context context) {
    super(context);
    Log.w("tablelayout","simple context");
    // TODO Auto-generated constructor stub
}

public Tablelayout_Schedrunning(Context context, AttributeSet attrs) {
    super(context, attrs);
    Log.w("tablelayout","advanced, context and attrs");
    // TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // TODO Auto-generated method stub
    int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
    int parentHeight = MeasureSpec.getSize(heightMeasureSpec);

    Log.w("tablelayout","parentWidth is " + parentWidth);
    Log.w("tablelayout","parentHeight is " + parentHeight);
    //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(parentWidth, (int) (parentHeight * .4));
}
4

1 に答える 1

1

私はあなたが追加super.onMeasuresetLayoutParams、あなたの拡張にView

于 2012-09-07T01:54:56.340 に答える