2013-07-12 6 views
1

나는 1 개 개의 전체 화면 안드로이드 활동 프로그래밍 방식을 작성해야합니다. 더미 콘텐츠는 다양한 구성 요소 (텍스트 뷰, 라디오 버튼, 체크 박스 ...)로 구성되며 동적으로 채워집니다. 1. 버튼에있다 : enter image description here안드로이드 레이아웃

Tthere가 의도 한대로 작동하지 않는 몇 가지 사항은 다음과 같습니다

다음
 //Main Layout 
    FrameLayout lLayout = new FrameLayout(this); 
    lLayout.setBackgroundColor(Color.parseColor("#0099cc")); 
    lLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT)); 
    //Navigation layout 
    LinearLayout l = new LinearLayout(this, null, R.style.ButtonBar); 
    LayoutParams bottomLayout = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT); 
    l.setLayoutParams(bottomLayout); 
    l.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL); 
    l.setBackgroundColor(Color.parseColor("#66000000")); 
    l.setOrientation(LinearLayout.HORIZONTAL); 


    LayoutParams buttLayout = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
    //previous section button 
    previousButton = new Button(this); 
    previousButton.setLayoutParams(buttLayout); 
    previousButton.setText("Previous section"); 
    previousButton.setOnClickListener(this); 
    l.addView(previousButton); 
    //next section button 
    Button nextButton = new Button(this); 
    nextButton.setLayoutParams(buttLayout); 
    nextButton.setText("Next section"); 
    nextButton.setOnClickListener(this); 
    l.addView(nextButton); 

    //add components 
    TextView tView = new TextView(this); 
    tView.setText("Dummy text"); 
    tView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT)); 
    lLayout.addView(tView); 
    lLayout.addView(l); 
    setContentView(lLayout); 

코드가 생성하는 것입니다 :

내가 지금까지 가지고있는 코드입니다 상단이 아닌 하단. 2. 단추가 멋지게 펼쳐지지 않습니다. 3. 단추 뒤에 테스트로 추가 된 TextView가 추가되었습니다. 화면에 여러 가지 위젯이 있으며 한 화면보다 커야합니다. 스크롤 옵션을 갖고 싶지만 화면 위 부분에있는 두 개의 버튼 뒤에 보이지 않는 모든 위젯을 갖고 싶습니다.

+1

왜 안드로이드 XML 편집기를 사용하여 레이아웃을 만들지 않으십니까? – Blackbelt

+0

XML로 이동 제안 –

+0

문제의 성격으로 인해 XML을 사용할 수 없습니다 ... – Jasko

답변

2

다음 XML은 당신이 필요로하는 것이 무엇인지 정확히 :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/dynamiclayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/navigationlayout" 
     android:orientation="vertical" > 
    </LinearLayout> 

    <RelativeLayout 
     android:id="@+id/navigationlayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:text="Previous Section" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:text="Next Section" /> 
    </RelativeLayout> 

</RelativeLayout> 

지금, 프로그램 dynamiclayout 을 팽창하고 그것으로 모든 동적 뷰를 추가 할 수 있습니다.

+0

내가 말했듯이이 모든 것을 프로그래밍 방식으로 개발해야하므로 XML을 사용할 수 없습니다. XML을 통해이를 수행하는 방법을 알고 있지만, 불행히도 하드 코딩은 내가 필요한 것입니다. – Jasko

+0

당신이 언급 한 모조품은 역동적으로 추가해야하는 내용입니까? 하단의 버튼은 항상 고정되어 있습니까? –

+0

준 사실. 예 더미 콘텐츠는 동적으로 생성되지만 XML을 사용하여 버튼을 만들 수는 없습니다. 이 화면을 기반으로하는 활동의 역동적 인 숫자를 갖게되며, 경우에 따라 버튼의 텍스트가 변경되고 때로는 하나 또는 다른 텍스트가 표시되지 않습니다. – Jasko

2

루트보기는 FrameLayout이며 하나의 하위보기에만 사용됩니다. FrameLayout의 모든 하위 항목이 화면의 같은 위치에 그려지기 때문에 겹쳐진보기를 만드는 데 자주 사용됩니다.

FrameLayoutRelativeLayout으로 바꿉니다. RelativeLayout.LayoutParams을 사용하려면 LayoutParams 참조를 업데이트해야합니다. 또한과 같이 부모보기의 하단에 정렬 탐색있는 LinearLayout을 설정해야합니다 :

RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
lps.addRule(RelativeLayout.LayoutParams.ALIGN_PARENT_BOTTOM, true); 

하지만 난 정말 XML을 사용하는 것이 좋습니다 것입니다. 그것은 당신의 삶을 훨씬 더 단순하게 만들 것입니다.

+0

XML을 사용하여이를 수행하는 방법을 알았습니다. 그러나 귀하의 의견은 다른 무엇을 위해 유용하므로 매우 감사드립니다. – Jasko