Android 我的文本视图没有显示…为什么?
我正在尝试创建一个列表视图,其下有一个文本视图。为了实现这一点,我在ListView中添加了一个页脚。我希望在ListView和TextView之间有一行,但我希望它有特定的边距。我创建了一个样式,然后将其添加到页脚。当我添加带有样式的视图时,它会将我的文本完全从屏幕上移开。以下是列表视图:Android 我的文本视图没有显示…为什么?,android,listview,footer,Android,Listview,Footer,我正在尝试创建一个列表视图,其下有一个文本视图。为了实现这一点,我在ListView中添加了一个页脚。我希望在ListView和TextView之间有一行,但我希望它有特定的边距。我创建了一个样式,然后将其添加到页脚。当我添加带有样式的视图时,它会将我的文本完全从屏幕上移开。以下是列表视图: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fil
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list_view_order_filter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="15dp"
android:layout_weight="1" >
</ListView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/orderFilters"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/order_filter" >
</Button>
<Button
android:id="@+id/orderFiltersCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/cancel" >
</Button>
</LinearLayout>
</LinearyLayout>
以下是我的风格:
<style name="divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:layout_marginRight">15dp</item>
<item name="android:layout_marginLeft">15dp</item>
<item name="android:layout_marginTop">10dp</item>
<item name="android:background">?android:attr/listDivider</item>
</style>
匹配父项
1dp
15dp
15dp
10dp
?android:attr/listDivider
这是我的页脚:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View style="@style/divider" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:gravity="left"
android:text="@string/total"
android:textStyle="bold" />
<TextView
android:id="@+id/orderTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:gravity="right"
android:textIsSelectable="true" />
</LinearLayout>
</LinearLayout>
这是我的观点的截图。页脚中的线性布局是水平的,但style=“@style/divider”视图具有布局\u宽度:匹配\u父视图。它会将随后出现的所有内容从屏幕上删除。这就是@style/divider中“匹配父对象”的问题 {
20dp
1dp
15dp
15dp
10dp
?android:attr/listDivider
}
试试这个,你将能够看到你的视图,之后根据需要调整宽度
你所能做的就是让你的线性布局垂直
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="40dp" >
<View style="@style/divider" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:gravity="left"
android:text="12000000"
android:textStyle="bold" />
<TextView
android:id="@+id/orderTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:gravity="right"
android:textIsSelectable="true" />
</LinearLayout>
试试这段代码。在这里,我将主xml和页脚合并到一个文件中。根据您的要求进行编辑
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list_view_order_filter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="15dp"
android:layout_weight="1" >
</ListView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/orderFilters"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="order_filter" >
</Button>
<Button
android:id="@+id/orderFiltersCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="cancel" >
</Button>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@drawable/icon" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:gravity="left"
android:text="total"
android:textColor="#3a6e9a"
android:textStyle="bold" />
<TextView
android:id="@+id/orderTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:gravity="right"
android:text="left"
android:textColor="#3a6e9a" />
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list_view_order_filter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="15dp"
android:layout_weight="1" >
</ListView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/orderFilters"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="order_filter" >
</Button>
<Button
android:id="@+id/orderFiltersCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="cancel" >
</Button>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@drawable/icon" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:gravity="left"
android:text="total"
android:textColor="#3a6e9a"
android:textStyle="bold" />
<TextView
android:id="@+id/orderTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:gravity="right"
android:text="left"
android:textColor="#3a6e9a" />
</LinearLayout>
</LinearLayout>