I have an adapter, where I display a list of webviews, each webview loads a news item with a different size text
<LinearLayout
android:id="@+id/layout_teste_tamanho"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.06"
android:scrollbars="none">
<WebView
android:id="@+id/news_txt_mensagem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|start"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:scrollbarStyle="insideOverlay"
android:scrollbars="none"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
What I wanted to do was set a maximum size for the webview not to exceed, eg 500dp and that when the news was small the small size of the news is kept, not the 500dp
I've already tried using the ViewTreeObserver inside the adapter
ViewTreeObserver viewObserver = holder.layoutTesteTamanho.getViewTreeObserver();
viewObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if(holder.layoutTesteTamanho.getHeight()>500){
holder.layoutTesteTamanho.getLayoutParams().height = 500;
}
}
});
However it displays the whole size of the news even if it is larger than 500, and only changes the size to 500 after I scroll down the