2014-04-17 1 views
0

이제 Listview의 레이아웃이 조금 엉망이되었습니다. 모든 행의 textviews가 이제는 화면을 가로로 채우는 동안 자유롭게 있어야합니다.ListView의 레이아웃이 겹쳐졌습니다.

EDIT : 현재 상황을보다 정확하게 설명하기 위해 텍스트를 업데이트했습니다. EDIT2 : 이것은 UI를 같이하도록되어 할 수 있습니다 :

위의 부분은이 같이 가정하고, 아래 부분은 현재 표시되는 것입니다 무슨이다.

내 ListView에 레이아웃 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal"> 

<TextView 
    android:id="@+id/goal_name" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_alignParentLeft="true"/> 

<LinearLayout 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:orientation="horizontal" 
    android:layout_centerHorizontal="true"> 

    <TextView 
     android:id="@+id/goal_progress" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"/> 

    <TextView 
     android:id="@+id/seperator" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:text="@string/seperator"/> 

    <TextView 
     android:id="@+id/goal_limit" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"/> 

    <!-- 
    <ProgressBar 
     android:id="@+id/progress_bar" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"/> 
    --> 

    </LinearLayout> 

</RelativeLayout> 

내 메인 페이지 레이아웃 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="nl.tizin.healthapp.GoalMainScreen$PlaceholderFragment"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_marginBottom="5dp"> 

    <TextView 
     android:id="@+id/name_header" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="@string/name_header_text" 
     android:textStyle="bold"/> 

    <TextView 
     android:id="@+id/day_header" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:text="@string/day_header_text" 
     android:textStyle="bold"/> 

</RelativeLayout> 

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

    <ListView 
     android:id="@+id/list_of_goals" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content">  
    </ListView> 

    <TextView 
     android:id="@+id/empty_goal_list" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/no_goals_added"/> 

</LinearLayout> 

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

    <Button 
     android:id="@+id/add_exercise_goal_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/add_exercise_goal_button_text" 
     android:onClick="addExerciseGoal"/> 

    <Button 
     android:id="@+id/add_food_goal_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/add_food_goal_button_text" 
     android:onClick="addFoodGoal"/> 

</LinearLayout> 

내에서 onCreate 방법 : 사람이 할 수있는 경우

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.goal_main_screen); 
    mGoalList = (ListView) findViewById(R.id.list_of_goals); 
    mGoalList.setEmptyView((View) findViewById(R.id.empty_goal_list)); 
    mGoalList.setOnItemClickListener(new OnItemClickListener(){ 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 
      Cursor c = (Cursor) mGoalList.getItemAtPosition(position); 
      //Get ID of goal and increment day value 
      checkInGoal(c.getInt(0)); 
      System.out.println(c.getString(1)); 
     } 
    }); 
    populateList(); 

나는 그것을 감사하겠습니다 도와주세요. 너무 오랫동안 이것을 쳐다 보았다.

답변

0

처음에는 목록보기 레이아웃이 RelativeLayout 태그를 닫지 않습니다.

당신은 속성을 추가 할 수 있습니다 : 당신의 LinearLayout

나는 가중치를 제안 할 수 있음 귀하의 의견에

android:layout_toRightOf="@+id/goal_name "

을 :

추가 속성 :

android:layout_weight="<some percentage>" 

각 012에 3,(예 : 0.8)

및 속성 다음 parent view

편집이 RelativeLayout의에있는 LinearLayout 변경처럼 보이는

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="1" 
     > 

     <TextView 
      android:id="@+id/goal_name_header" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:layout_weight=".3" 
      android:text="Goal Name Header" 

      /> 

     <TextView 
      android:id="@+id/goal_progress_header" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".7" 
      android:gravity="left" 
      android:text="Progress Header" 

      /> 

    </LinearLayout> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="1" 
     > 

     <TextView 
      android:id="@+id/goal_name" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".3" 
      android:gravity="left" 
      android:text="Goal Name " 

      /> 

     <TextView 
      android:id="@+id/goal_progress" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight=".7" 
      android:gravity="left" 
      android:text="Progress " 

      /> 


    </LinearLayout> 

</LinearLayout> 
+0

죄송합니다. 코드를 올바르게 붙여 넣지 않았기 때문입니다. 나는 항구를 바로 편집 할 것이다. – Anubis

+0

제안 사항은 텍스트보기가 더 이상 겹쳐지지 않지만 여전히 뭉친 상태라는 점에서 도움이되었습니다. android : layout_centerHorizontal 태그가 무시당하는 것 같습니다. – Anubis

+0

현재 유일한 문제는 android : layout_centerHorizontal 및 android : layout_alignParentLeft 태그에 의해 지시 된대로 화면을 채우는 동안 목록보기의 내용이 래핑 된 것처럼 보이는 것입니다. – Anubis

0

android:weightSum="1" 

. RelativeLayout 태그를 닫고 orientation 특성을 제거하십시오.

+0

RelativeLayout이 제대로 닫혔지만 코드가 제대로 포맷되지 않아서 게시물에 표시되지 않았습니다. – Anubis

+0

RelativeLayouts에서 방향 속성을 제거하는 방법은 무엇입니까? – dharms

+0

방향 속성을 제거해도 아무 것도 수행하지 않습니다. – Anubis

관련 문제