相关疑难解决方法(0)

Android获得Fragment宽度

我有一个包含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>
Run Code Online (Sandbox Code Playgroud)

在第一个片段中,我有一个TableLayout,其中每行有一个自定义TextView.我想知道片段的宽度,因为如果自定义TextView比片段宽,我将设置所需的行数.

这是我在自定义TextView中所做的:

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

mMaxWidth = (float) (getMeasuredWidth());
}
Run Code Online (Sandbox Code Playgroud)

通过这一行,我得到了三个片段的宽度,而不仅仅是包含自定义TextView的片段.

谢谢.

android fragment width textview

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

fragment ×1

textview ×1

width ×1