Android 如何从片段中获取高度并设置viewpager的高度?
我有麻烦了 我试图从如下布局的片段中获取高度:Android 如何从片段中获取高度并设置viewpager的高度?,android,user-interface,android-fragments,android-viewpager,Android,User Interface,Android Fragments,Android Viewpager,我有麻烦了 我试图从如下布局的片段中获取高度: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/container_fra
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container_frag_informacoes_detalhes"
tools:context="br.com.magazineluiza.mobilevendas.userinterface.detalhesproduto.FragInformacoesDetalhesProduto">
<TextView
android:id="@+id/tv_frag_information_detalhes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/loren_ipsum"/>
它从@string/loren_ipsum获取一个大文本
我想知道它的高度,但我做不到
我该怎么做呢?怎么样:
TextView tv = (TextView) getActivity().findViewbyId(R.id.tv_frag_information_detalhes);
final int height = tv.getHeight();
在onCreateView中。我已尝试执行此操作,但返回0。我仍然试图获得线性布局的高度、片段视图以及两者的测量高度。我还尝试在ViewTreeObserver.OnGlobalLayoutListener()中获取它,但它也返回了0。我刚刚尝试创建一个自定义viewPager并编辑onMeasure,但它的大小调整为错误的值try View.post()