저는 가로 및 세로 스크롤을 지원하는 안드로이드 애플리케이션을 만들고 있습니다. 나는 ViewGroup을 기초로 두었습니다.. 나는 을로드했습니다. 뷰 그룹 내에 수직 스크롤 막대 (FrameLayout에서 확장 됨)이로드되었습니다. 세로 스크롤 막대에는 가로 스크롤 막대 (FrameLayout에서 파생 됨)이 자식으로 포함되어 있습니다. 내 생각은 에 HorizontalScrollbar 내에서 LinearLayout을 추가하여 둘 이상의 자식을 선형 적으로 추가 할 수 있습니다. 그러나 은 HorizontalScrollBar 내부에 추가 한 레이아웃 내에 하나 이상의 LinearLayout을 추가 할 수 없습니다. 레이아웃 내에 하나 이상의 레이아웃을 추가 할 수 없습니다.
나는이 방법을 시도했다.
private VScrollViewer Vscroll;
//VScrollViewer is a class extended from android.widget.ScrollView
public AndroidGrid(Context paramContext)
{
super(paramContext);
init();
}
public void init()
{
Vscroll = new VScrollViewer(getContext());
LinearLayout lr=new LinearLayout(getContext());
LinearLayout lr1=new LinearLayout(getContext());
LinearLayout lr2=new LinearLayout(getContext());
lr.setOrientation(LinearLayout.VERTICAL);
lr1.setOrientation(LinearLayout.VERTICAL);
lr2.setOrientation(LinearLayout.VERTICAL);
lr.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
LinearLayout hlr= new LinearLayout(getContext());
hlr.setOrientation(LinearLayout.HORIZONTAL);
for(int i = 20; i < 550; i+=20){
TextView myText = new TextView(getContext());
myText.setY(i*3);
myText.setText("HELLLLLOOOO");
lr.addView(myText);
lr1.addView(myText);
lr2.addView(myText);
}
hlr.addView(lr);
hlr.addView(lr1);
hlr.addView(lr2);
Vscroll.container.addView(hlr);
addView(Vscroll);
}
오류 로그 :
이11-12 10:04:57.031: E/AndroidRuntime(18425): FATAL EXCEPTION: main
11-12 10:04:57.031: E/AndroidRuntime(18425): Process: com.example.baseexample, PID: 18425
11-12 10:04:57.031: E/AndroidRuntime(18425): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.baseexample/com.example.baseexample.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class com.example.baseexample.AndroidGrid
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.app.ActivityThread.access$800(ActivityThread.java:139)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.os.Handler.dispatchMessage(Handler.java:102)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.os.Looper.loop(Looper.java:136)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.app.ActivityThread.main(ActivityThread.java:5086)
11-12 10:04:57.031: E/AndroidRuntime(18425): at java.lang.reflect.Method.invokeNative(Native Method)
11-12 10:04:57.031: E/AndroidRuntime(18425): at java.lang.reflect.Method.invoke(Method.java:515)
11-12 10:04:57.031: E/AndroidRuntime(18425): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-12 10:04:57.031: E/AndroidRuntime(18425): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-12 10:04:57.031: E/AndroidRuntime(18425): at dalvik.system.NativeStart.main(Native Method)
11-12 10:04:57.031: E/AndroidRuntime(18425): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class com.example.baseexample.AndroidGrid
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
11-12 10:04:57.031: E/AndroidRuntime(18425): at com.example.baseexample.MainActivity.onCreate(MainActivity.java:14)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.app.Activity.performCreate(Activity.java:5248)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
11-12 10:04:57.031: E/AndroidRuntime(18425): ... 11 more
11-12 10:04:57.031: E/AndroidRuntime(18425): Caused by: java.lang.reflect.InvocationTargetException
11-12 10:04:57.031: E/AndroidRuntime(18425): at java.lang.reflect.Constructor.constructNative(Native Method)
11-12 10:04:57.031: E/AndroidRuntime(18425): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
11-12 10:04:57.031: E/AndroidRuntime(18425): ... 22 more
11-12 10:04:57.031: E/AndroidRuntime(18425): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.view.ViewGroup.addViewInner(ViewGroup.java:3564)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.view.ViewGroup.addView(ViewGroup.java:3417)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.view.ViewGroup.addView(ViewGroup.java:3362)
11-12 10:04:57.031: E/AndroidRuntime(18425): at android.view.ViewGroup.addView(ViewGroup.java:3338)
11-12 10:04:57.031: E/AndroidRuntime(18425): at com.example.baseexample.AndroidGrid.init(AndroidGrid.java:55)
11-12 10:04:57.031: E/AndroidRuntime(18425): at com.example.baseexample.AndroidGrid.<init>(AndroidGrid.java:28)
11-12 10:04:57.031: E/AndroidRuntime(18425): ... 25 more
사람이 나에게있는 LinearLayout의 HLR 내부에있는 LinearLayout의 LR1과 LR2를 추가하는 방법을 제안 할 수 이것은 내 코드?
오류 로그를 게시하십시오. –
스크롤 가능보기는 스크롤 가능 하위를 포함 할 수 없습니다. –