У меня есть макет с 3 фрагментами:
<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>
В первом фрагменте у меня есть TableLayout, в котором у меня есть один пользовательский TextView в каждой строке. Я хочу знать ширину фрагмента, потому что, если пользовательский TextView шире, чем фрагмент, я установлю необходимое количество строк.
Вот что я сделал в своем пользовательском TextView:
@Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mMaxWidth = (float) (getMeasuredWidth());
}
С помощью этой строки я получил ширину из трех фрагментов, а не только того, который содержит пользовательский TextView.
Спасибо.