Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从片段中获取高度并设置viewpager的高度?_Android_User Interface_Android Fragments_Android Viewpager - Fatal编程技术网

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()