2014-10-28 2 views
1

선형 레이아웃을 부모로 사용하고 그 안에 두 개의 자식 선형 레이아웃이 있습니다. 나는 로 사용하여이 부모를 시도 아래쪽 여백을 메인은 LinearLayouts 일치해야합니다 버튼의 화면이나 아래쪽 여백의 바닥에LinearLayout에서 화면 아래쪽에 버튼을 정렬하는 방법

RelativeLayout의를

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

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:id="@+id/parentlayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:orientation="vertical" > 
    </LinearLayout> 
</ScrollView> 

<LinearLayout 
    android:id="@+id/buttons" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="bottom" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/save" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Save" /> 

    <Button 
     android:id="@+id/submit" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Submit" /> 

    <Button 
     android:id="@+id/cancel" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Cancel" /> 

    <Button 
     android:id="@+id/delete" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Delete" /> 

    <Button 
     android:id="@+id/reset" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Reset" /> 
    </LinearLayout> 
</LinearLayout> 
+0

나는 당신의 문제가 무엇 모르는, 내가 통해 UR 코드를 가져다가 일식과 버튼에서 볼 화면 하단에 이미 정렬되어 있습니다 –

답변

1

버튼 텍스트의 textsize 만 줄이면됩니다. 한 줄에 텍스트를 표시 할 수 없으므로 여백이 왜곡됩니다. 여기

나는 각 buttontext에 대한 11dp에 TEXTSIZE를 만든 및보기가 NexusOne 크기의 디스플레이에 적합

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

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <LinearLayout 
      android:id="@+id/parentlayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top" 
      android:orientation="vertical" > 
     </LinearLayout> 
    </ScrollView> 

    <LinearLayout 
     android:id="@+id/buttons" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="bottom" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/save" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Save" 
      android:textSize="11dp" /> 

     <Button 
      android:id="@+id/submit" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Submit" 
      android:textSize="11dp" /> 

     <Button 
      android:id="@+id/cancel" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Cancel" 
      android:textSize="11dp" /> 

     <Button 
      android:id="@+id/delete" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Delete" 
      android:textSize="11dp" /> 

     <Button 
      android:id="@+id/reset" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Reset" 
      android:textSize="11dp" /> 
    </LinearLayout> 

</LinearLayout> 
+0

네, 이것도 나를 위해 일했습니다. 하지만 id = parentlayout 값의 데이터가 textviews/edittexts와 겹치게되면 데이터가 작동할까요? – user3706655

+0

기본 XML 레이아웃이'LinearLayout'이므로 작동 할 것입니다. 하단 선형 배치의 '버튼'은 그곳에 머무를 것입니다. 'id = parentlayout'에 무엇을 추가하든'scrollview' 안에 들어갈 것입니다. 원한다면'parentlayout'에 몇 가지 요소를 추가하여 예제를 보여줄 수 있습니다. –

+1

예 완벽하게 작동합니다. – user3706655

1

을 마지막있는 LinearLayout에서 버튼을 정렬 할

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:id="@+id/parentlayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:orientation="vertical" > 
    </LinearLayout> 
</ScrollView> 

<LinearLayout 
    android:id="@+id/buttons" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_gravity="bottom" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/save" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Save" /> 

    <Button 
     android:id="@+id/submit" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Submit" /> 

    <Button 
     android:id="@+id/cancel" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Cancel" /> 

    <Button 
     android:id="@+id/delete" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Delete" /> 

    <Button 
     android:id="@+id/reset" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Reset" /> 
</LinearLayout> 

+0

내 안에 TableLayout을 사용하여 relativelayouts를 완벽하게 사용했습니다. 그러나 이제는 LinearLayout과 함께 작업하고 싶습니다. – user3706655

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

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <LinearLayout 
       android:id="@+id/parentlayout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="top" 
       android:orientation="vertical" > 
      </LinearLayout> 
     </ScrollView> 
    </LinearLayout> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="bottom" 
      android:orientation="vertical" > 

      <LinearLayout 
       android:id="@+id/buttons" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="bottom" 
       android:orientation="horizontal" > 

       <Button 
        android:id="@+id/save" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Save" 
        android:textSize="12sp" /> 

       <Button 
        android:id="@+id/submit" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Submit" 
        android:textSize="12sp" /> 

       <Button 
        android:id="@+id/cancel" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Cancel" 
        android:textSize="12sp" /> 

       <Button 
        android:id="@+id/delete" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Delete" 
        android:textSize="12sp" /> 

       <Button 
        android:id="@+id/reset" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:text="Reset" 
        android:textSize="12sp" /> 
      </LinearLayout> 
     </LinearLayout> 
    </FrameLayout> 
</FrameLayout> 

+0

안녕하세요.이 기능 덕분에 완벽하게 작동했습니다. 하지만 왜 우리는 버튼에 선형 레이아웃 트리를 사용해야합니까? android : id = "@ + id/parentlayout"의 데이터 목록이 증가하면 텍스트가 버튼과 겹치지 않을까요? – user3706655

1

이러한 종류의 요구 사항에 대해 RelativeLayout을 사용하면 더 좋습니다. 번거 로움없이 일하게 될 것입니다.

<?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" 
android:orientation="vertical" > 

<ScrollView 
android:layout_width="match_parent" 
android:layout_height="wrap_content" > 

<LinearLayout 
    android:id="@+id/parentlayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="top" 
    android:orientation="vertical" > 
</LinearLayout> 
</ScrollView> 

<LinearLayout 
android:id="@+id/buttons" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="bottom" 
android:layout_alignParentBottom="true" 
android:orientation="horizontal" > 

<Button 
    android:id="@+id/save" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Save" /> 

<Button 
    android:id="@+id/submit" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Submit" /> 

<Button 
    android:id="@+id/cancel" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Cancel" /> 

<Button 
    android:id="@+id/delete" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Delete" /> 

<Button 
    android:id="@+id/reset" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Reset" /> 
</LinearLayout> 
</RelativeLayout> 
관련 문제