Android Fragment erhalten Breite

Ich habe ein layout mit 3 Fragmenten:

<LinearLayout android:id="@+id/acciones"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<LinearLayout
android:id="@+id/fragment1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

</LinearLayout>


<LinearLayout
android:id="@+id/fragment2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:id="@+id/f3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

</LinearLayout>

</LinearLayout>

In das erste fragment habe ich ein TableLayout, in dem ich eine benutzerdefinierte TextView in jeder Zeile.
Ich möchte wissen, die Breite des fragments, weil, wenn die benutzerdefinierte TextView ist breiter als das fragment, ich werde legen Sie die Anzahl der Zeilen erforderlich.

Dies ist, was ich getan habe in meinem custom TextView:

@Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

mMaxWidth = (float) (getMeasuredWidth());
}

Mit dieser Zeile bekam ich die Breite von den drei Fragmente, nicht nur das eine enthält die benutzerdefinierte TextView.

Dank.

InformationsquelleAutor gutiory | 2012-03-23

Schreibe einen Kommentar