Note that there are some explanatory texts on larger screens.

plurals
  1. POScrollView makes a custom layout invisible
    text
    copied!<p>I made a custom <code>Viewgroup</code> which i need to use in my application, but i need to put it in a <code>ScrollView</code>. When the layout is made only with my custom <code>ViewGroup</code> everything works fine, but when I put it in a <code>ScrollView</code> i can't see anything. My layout:</p> <pre><code>&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;com.example.test.CustomLayout android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;/com.example.test.CustomLayout&gt; &lt;/ScrollView&gt; </code></pre> <p>My viewgroup:</p> <pre><code>protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ super.onMeasure(widthMeasureSpec, heightMeasureSpec); /* do something and call for each child View v = getChildAt(i); v.measure(wspec, hspec); */ setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); } protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //do something and call layout on every child } </code></pre> <p>UPDATE: My CustomLayout class</p> <pre><code>public class CustomLayout extends ViewGroup{ /*My params*/ public CustomLayout(Context context) { super(context); // TODO Auto-generated constructor stub } public CustomLayout(Context context, AttributeSet attrs) { super(context, attrs); } public CustomLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //do something and call layout on every child } protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ super.onMeasure(widthMeasureSpec, heightMeasureSpec); /* do something and call for each child View v = getChildAt(i); v.measure(wspec, hspec); */ setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); } } </code></pre> <p>UPDATE 2: Sorry but I made some other tries and it looks like if I have the viewgroup in a scrollview on the onMeasure method i got heightMeasureSpec = 0, then if I put the viewgroup in any other layout, i got an integer. Maybe this would help?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload