2012-01-23 7 views
2

활동에서 DB의 데이터를 표시하고 있습니다. 나는 테이블과 버튼을 바닥에두고 싶다. 데이터에 대해서는 TableLayout이 최선의 선택이라고 생각했습니다. TableLayout을 HorizontalView에 추가했습니다. &이 ScrollView에 수직으로 스크롤됩니다. & 가로. 머리글을 포함하여 모든 행을 동적으로 추가합니다. 이 부분은 잘 작동합니다.Android : 원하는대로 TableLayout을 올바르게 설정할 수 없습니다.

내용이 화면 너비보다 작 으면 전체 화면 너비를 차지해야합니다. 예를 들면. 테이블이 Portrait 모드에 잘 맞으면, Landscape 모드에서 오른쪽에 공백이 생깁니다. 나는 그 공간이 비어있는 대신에 모든 칸을 차지하고 싶다. 행 너비가 화면 너비보다 크면 아무런 문제가 없습니다. 즉, 가로 스크롤 막대가 나타납니다.

몇 가지 변형을 시도했지만 아무런 도움이되지 않았습니다. 모든 공간을 utlize하기 위해 어떤 설정을 할 것인지 (어떤 경우 든 avbl) &이 표시됩니다.

그리고 예, 수평 스크롤바 1 호 이상이 마지막 행에 나타납니다. 마지막 행 아래에 이 나타나기를 원합니다 - 그래서 마지막 행의 경계가 보입니다. 내 XML :

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:orientation="vertical"> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:scrollbars="horizontal|vertical"> 

<HorizontalScrollView android:layout_width="wrap_content" android:layout_height="wrap_content" 
android:layout_marginTop="10dp" android:layout_marginBottom="10dp" > 

<TableLayout android:id="@+id/browseTable" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:layout_marginBottom="20dp" 
    android:background="#FF0000" android:stretchColumns="1,2,3"> 

</TableLayout> 

</HorizontalScrollView> 
</ScrollView> 

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="wrap_content" 
android:orientation="horizontal" android:gravity="center" 
android:layout_marginTop="15dp"> 
    <Button android:id="@+id/browseAddBtn" android:text="Add" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginRight="10dp" /> 
    <Button android:id="@+id/browseViewBtn" android:text="Edit" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginRight="10dp" /> 
    <Button android:id="@+id/browseReturnBtn" android:text="Return" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" />   
    </LinearLayout> 

</LinearLayout> 

출력 : enter image description here

+0

이 이미지를 캡처하여 여기에 추가 한 다음 정확히 무엇을 원하는지 말할 수 있습니다. 그러면 다른 도움을받을 수 있습니다. :) 감사합니다 – AAnkit

+0

@AnkitA, 내가 가지고있는 이미지를 추가하고 내가 원하는 것을 설명합니다. 다른 사람들이 나를 도울 수 있기를 바랍니다. – Tvd

+0

내 대답을 시도해보십시오. 그렇지만 모든 문제는 해결할 수 없습니다. float 값을 표시하려는 경우 초입니다. 길이까지 보여 주려고 노력하십시오.십진수 후 4 자리를 좋아해요. – AAnkit

답변

4

레이아웃 코드 아래에 의해 해결됩니다. Horizontal Scroll View에서 Table Layout을 사용할 때 android : stretchColumns이 작동하지 않습니다. 화면을 회전 시키거나 열의 너비 데이터가 작을 때 빈 공간이 생기는 것입니다.

이 내용을 이해하시기 바랍니다. Horizontal Scroll View를 다른 것으로 대체하여이 문제를 해결하기 위해 노력하고 있습니다. 해결책을 찾으면 답을 게시 할 것입니다. 안녕. 편집

안녕 TVD

마침내 나는 당신의 문제에 대한 해결책을 얻었다. XML 레이아웃 파일을 아래와 같이 변경하십시오.

TableLayout을에서 사용

 android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true" 

사용 stretchColumns = "*"

<HorizontalScrollView>에서 모든 열이 늘어하려는 경우.

안녕히 계십시오. :-)

+0

OH @Yugandhar Babu, 매우 우수합니다. fillViewPort가 작업을 수행했습니다. 이전에이 질문을 했었지만 제대로 반응하지는 못했습니다. 당신의 팁은 나를 도왔습니다. 헬프 라인에 대단히 감사드립니다. 고마워. 내가 20 일 이상을 추측했기 때문에 이것이 내 ToDo 목록에 있다는 것을 알 수 없습니다. 몇 가지 시도했지만 원하는 결과를 얻지 못했습니다. 다시 한번 감사합니다. – Tvd

+0

당신은 오신 것을 환영합니다. –

+0

@ YugandharBabu이 문제를 해결하려고했지만 실패했습니다. 잘 했어. –

0

나는 일부 변경했다. 문제의 일부는 HorizontalScrollView 내에서 사용하는 경우 문제에 대한 TableLayout을를 해결하는 동안 나는 한 가지를 발견

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

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:scrollbars="horizontal|vertical" > 

    <HorizontalScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:layout_marginTop="10dp" > 

     <TableLayout 
      android:id="@+id/browseTable" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dp" 
      android:background="#FF0000" > 
     </TableLayout> 
    </HorizontalScrollView> 
</ScrollView> 

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    style="@android:style/ButtonBar" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/browseAddBtn" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="10dp" 
     android:layout_weight="1" 
     android:text="Add" /> 

    <Button 
     android:id="@+id/browseViewBtn" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="10dp" 
     android:layout_weight="1" 
     android:text="Edit" /> 

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

+0

ScrollView에서 layout_weight 변경 사항을 추가했지만 그 점이 도움이되지 않았습니다. 결과가 변경되지 않았습니다. – Tvd

+0

"ButtonBar"스타일 아이디어가 마음에 들었습니다. 나는 그것도 바닥에 넣고 싶었지만 같은 것을위한 길을 얻지 못했습니다. 스타일 아이디어가 트릭을 만들었습니다. ButtonBar 스타일 아이디어에 감사드립니다. – Tvd

+0

수평으로 채우기 위해 부모를 채우십시오.보기를 스크롤하고 도와 주도록하십시오. AAnkit

관련 문제