안녕하세요 저는 레이아웃을 동적으로 만들려고하고 있으며 스크롤 할 수 있어야합니다. 얼마나 많은 텍스트 필드를 알고 텍스트 필드를 편집해야하는지 알 수 없기 때문입니다. 그림은 아래와 같습니다. 스크롤 가능한 레이아웃을 만드는 방법
1
A
답변
2
부모 레이아웃 (LinearLayout 또는 RelativeLayout)을 ScrollView
에 입력하십시오. 이 모든 것을 해결할 필요가 있습니다. 먼저 아래와 같이이 XML 파일을 생성하고 콘텐츠를보기에 그를 설정할 수 있습니다 자바 파일에 대해
ScrollView scroll = new ScrollView(this);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
LinearLayout layout=new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
scroll.addView(layout,
new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
setContentView(scroll);
+0
내 업데이트 된 답변보기 – waqaslam
1
이 작업을 수행하는 레이아웃이 있습니다. ScrollView을 사용하십시오.
편집 :
LinearLayout layout=new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
ScrollView scrollLayout = new ScrollView(this);
scrollLayout.addView(layout);
setContentView(scrollLayout);
그리고 layout
그냥 모든 컨트롤 :이 같은 뭔가를 할 수
.
+0
어떻게하면 java 파일로 구현할 수 있습니까? Java 파일에서 레이아웃을 동적으로 생성합니다. – answer88
1
대신이 라인의
LinearLayout layout=new LinearLayout(this);
보다
RelativeLayout linearMain = (LinearLayout) findViewById(R.id.RelativeLayout02);
및 이 내부에 내 의견을 추가하는 것보다
linearMain.addView(button);
위의 행은 여러분의 의견을 추가합니다.
는<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/RelativeLayout02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
..............
your views
</RelativeLayout>
</ScrollView>
3
ScrollView scrollView = new ScrollView(this);
LinearLayout linear = new LinearLayout(this);
EditText ed1 = new EditText(this);
EditText ed2 = new EditText(this);
linear.add(ed1); <-- Add all views to Relative layout dynamically
linear.add(ed2); <-- Add all views to Relative layout dynamically
scrollView.addView(linear); <-- Then add only LinearLayoutto ScrollView
있는 ScrollView 직접 하나의 아이를 가질 수 있습니다.
setContentView(scrollView);
XML에서 scrollview를 사용하십시오. 그런 다음 런타임에 다른보기를 추가하십시오. –
@ answer88 귀하의 xml 파일을 게시하십시오. –
자바 파일로 만들려고합니다. – answer88