这是我的布局文件。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ActivityMain">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbarLayer"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ListView
android:id="@+id/users"
android:layout_marginTop="40dp"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbarLayer"
android:layout_above="@+id/button_add_new_user"
/>
<Button
android:id="@+id/button_add_new_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add New User"
android:layout_alignParentBottom="true"
/>
</android.support.design.widget.CoordinatorLayout>
我想在活动底部显示一个按钮。但上面的代码没有显示按钮。
任何人都可以帮我解决这里的问题吗?
答案 0 :(得分:1)
这将正确对齐您的相对布局,包括工具栏下方的Listview(上方按钮)和按钮(父级底部对齐)。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbarLayer"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbarLayer"
android:layout_marginTop="?attr/actionBarSize"
>
<ListView
android:id="@+id/users"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/button_add_new_user"
/>
<Button
android:id="@+id/button_add_new_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add New User"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
答案 1 :(得分:0)
将listview和按钮包裹在这样的relativelayout中:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ActivityMain">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbarLayer"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/users"
android:layout_marginTop="40dp"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbarLayer"
android:layout_above="@+id/button_add_new_user"
/>
<Button
android:id="@+id/button_add_new_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add New User"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
现在应该可以了。
答案 2 :(得分:0)
require(ggmap)
map.background <- get_map(c(lon = -122, lat = 47.5), map = "toner-background")
map.lines <- get_map(c(lon = -122, lat = 47.5), map = "toner-lines")
map.labels <- get_map(c(lon = -122, lat = 47.5), map = "toner-labels")
set.seed(127)
df <- data.frame(lon = rnorm(25, mean = -122.2, sd = 0.2),
lat = rnorm(25, mean = 47.5, sd = 0.1),
size = rnorm(25, mean = 15, sd = 5))
ggmap(map.background) +
geom_point(data = df,
aes(x = lon, y = lat, size = size),
color = "blue", alpha = 0.8) +
scale_size_identity(guide = "none") +
inset_ggmap(map.lines) +
inset_ggmap(map.labels)
应用程式:popupTheme =&#34; @风格/ AppTheme.PopupOverlay&#34; /&GT;
<android.support.design.widget.AppBarLayout
android:id="@+id/toolbarLayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
答案 3 :(得分:0)
使用此代码..
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbarLayer">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbarLayer"
android:layout_marginTop="?attr/actionBarSize"
>
<ListView
android:id="@+id/users"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/button_add_new_user"
/>
<Button
android:id="@+id/button_add_new_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add New User"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>