刚才我的Listview中的布局有点混乱:现在每行中的文本视图都被包装,而它们应该可以自由地水平填充屏幕。
编辑:更新文本以更准确地描述当前情况。 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 :(得分:0)
对于初学者,您的列表视图布局不会关闭RelativeLayout
标记。
您可能想要添加属性:
android:layout_toRightOf="@+id/goal_name
&#34;
在LinearLayout
我建议加权你的意见:
添加属性:
android:layout_weight="<some percentage>"
每个child view
中的(即:.8)
和属性:
android:weightSum="1"
到parent view
修改强>
<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>
答案 1 :(得分:0)
看起来您已从LinearLayout更改为RelativeLayout。关闭RelativeLayout标记并删除orientation属性。