我有一个包含3个片段的布局:
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
android:id="@+id/fragment1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
android:id="@+id/fragment2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
android:orientation="vertical"
android:id="@+id/f3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
在第一个片段中,我有一个TableLayout,其中每行有一个自定义TextView.
我想知道片段的宽度,因为如果自定义TextView比片段宽,我将设置所需的行数.
这是我在自定义TextView中所做的:
@Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mMaxWidth = (float) (getMeasuredWidth());
}
通过这一行,我得到了三个片段的宽度,而不仅仅是包含自定义TextView的片段.
谢谢.