मैंने कस्टम Viewgroup
बनाया है जिसे मुझे अपने एप्लिकेशन में उपयोग करने की आवश्यकता है, लेकिन मुझे इसे ScrollView
में रखना होगा। जब लेआउट केवल मेरे कस्टम ViewGroup
के साथ किया जाता है तो सब ठीक काम करता है, लेकिन जब मैं इसे ScrollView
में डालता हूं तो मुझे कुछ भी दिखाई नहीं दे रहा है। मेरे लेआउट:स्क्रॉलव्यू एक कस्टम लेआउट अदृश्य बनाता है
<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" >
<com.example.test.CustomLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</com.example.test.CustomLayout>
</ScrollView>
मेरे viewgroup:
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
}
अद्यतन: मेरे CustomLayout वर्ग
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));
}
}
अद्यतन 2: क्षमा करें, लेकिन मैं कुछ अन्य की कोशिश करता बना दिया है और यह अगर की तरह दिखता है मेरे पास ऑनमेज़र विधि पर स्क्रॉलव्यू में व्यू ग्रुप है, मुझे ऊंचाई मिलीमीटर = 0 मिली है, तो अगर मैं व्यूग्रुप को किसी अन्य लेआउट में डालता हूं, मुझे एक पूर्णांक मिला। शायद यह मदद करेगा? layout_height match_parent को
कि कोशिश की, कोई परिणाम की तरह
उपयोग कोड के नीचे जोड़ें। – DLock