Android 为什么我的按钮没有显示在布局中?
我一直在做一个带有列表视图的选项卡式活动。我一直在尝试在列表视图下放置一个按钮,但是当我在手机上运行时,按钮没有显示出来 我的片段布局Android 为什么我的按钮没有显示在布局中?,android,android-layout,Android,Android Layout,我一直在做一个带有列表视图的选项卡式活动。我一直在尝试在列表视图下放置一个按钮,但是当我在手机上运行时,按钮没有显示出来 我的片段布局 <FrameLayout 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"
<FrameLayout 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"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="@+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorRedPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/item_detected"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_data"
android:layout_below="@id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@color/colorRedPrimary"
android:text="@string/register_all_item"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</FrameLayout>
我的android studio中的我的布局预览
在手机上运行时的布局(我使用的是华硕Zenfone 5)
我不确定我哪里做错了,我实际上已经把按钮改成了浮动按钮,但是只有一半的按钮显示在布局中。(另外,我无法滚动布局)
更新
我已经解决了,问题在选项卡式活动布局中。
我使用约束布局作为父级,我已将其更改为相对布局,它工作得非常完美请尝试以下代码
<FrameLayout 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"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="@+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorRedPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/item_detected"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_data"
android:layout_below="@id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_above="@+id/btn_register" />
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@color/colorAccent"
android:text="submit"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</RelativeLayout>
试试这段代码
<FrameLayout 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"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="@+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorRedPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/item_detected"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_data"
android:layout_below="@id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_above="@+id/btn_register" />
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@color/colorAccent"
android:text="submit"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</RelativeLayout>
这是因为按钮上方的视图中有“匹配父项”属性。因此,按钮不会显示,因为按钮上方的视图已设置为占用父项的所有空间
请参见下面的代码修改
<FrameLayout
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"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="@+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorRedPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/item_detected"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_data"
android:layout_below="@id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@color/colorRedPrimary"
android:text="@string/register_all_item"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</FrameLayout>
您可以尝试使用本文中解释的weightSum。
这是因为按钮上方的视图中有“匹配父级”属性。因此按钮不会显示,因为按钮上方的视图已设置为占用父级的所有空间
请参见下面的代码修改
<FrameLayout
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"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="@+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorRedPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/item_detected"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_data"
android:layout_below="@id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@color/colorRedPrimary"
android:text="@string/register_all_item"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</FrameLayout>
您可以尝试使用本文中解释的weightSum。
它对父布局的划分提供了更多的控制请尝试使用此代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="@+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Items Detected"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/btn_register"
android:layout_below="@+id/rl_total_data"/>
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorAccent"
android:text="Register"
android:textAllCaps="false"
android:textColor="#fff" />
尝试使用此代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="@+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Items Detected"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/btn_register"
android:layout_below="@+id/rl_total_data"/>
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorAccent"
android:text="Register"
android:textAllCaps="false"
android:textColor="#fff" />
试试这个
根据你的喜好改变颜色
<FrameLayout 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"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="@+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="detected"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff"
android:layout_marginRight="7dp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_data"
android:layout_below="@id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@color/colorPrimary"
android:text="helo"
android:textAllCaps="false"
android:textColor="#fff"
android:layout_alignParentLeft="true" />
</RelativeLayout>
</FrameLayout>
试试这个
根据你的喜好改变颜色
<FrameLayout 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"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp">
<RelativeLayout
android:id="@+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="detected"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff"
android:layout_marginRight="7dp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_data"
android:layout_below="@id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@color/colorPrimary"
android:text="helo"
android:textAllCaps="false"
android:textColor="#fff"
android:layout_alignParentLeft="true" />
</RelativeLayout>
</FrameLayout>
试试这个
<FrameLayout 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"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorRedPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/item_detected"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_data"
android:layout_below="@id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@color/colorRedPrimary"
android:text="@string/register_all_item"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
试试这个
<FrameLayout 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"
tools:context="com.siscaproject.sisca.Fragment.RegisterFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="7dp"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorRedPrimary"
android:padding="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/item_detected"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_total_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="7dp"
android:hint="10 items detected"
android:textColor="#fff" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_data"
android:layout_below="@id/rl_total_data"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:id="@+id/lv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
<Button
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@color/colorRedPrimary"
android:text="@string/register_all_item"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
不幸的是,仍然有相同的输出。这是运行时问题。将这一行传递到listview android:layout_over=“@+id/btn_register”我更新listview xml代码并添加上面的注释行代码仍然不起作用,也许你需要我的选项卡式活动布局?仍然有相同的输出不幸的是这是运行时问题。将这一行传递到listview android:layout_over=“@+id/btn_register”我更新listview xml代码并添加上面的注释行代码仍然不起作用,也许您需要我的选项卡式活动布局?仍然具有相同的输出请参见修改后的代码,列表视图也不应与家长匹配仍然具有相同的输出请参见修改后的代码,列表视图也不应与家长匹配仍然具有相同的输出您可以显示您的活动布局吗。因为这个片段布局在设备中运行良好,所以我的活动布局使用了协调器布局,而不是相对布局。我已经改变了,我现在工作很好。谢谢你的回答!仍然有相同的输出您可以显示您的活动布局。因为这个片段布局在设备中运行良好,所以我的活动布局使用了协调器布局,而不是相对布局。我已经改变了,我现在工作很好。谢谢你的回答!我已经解决了,问题在我的选项卡式活动布局中。你应该看到我的更新信息上面。谢谢你的回答@我对活动的安排也很好奇,但我迟到了。谢谢你通知我更新。我已经解决了,问题在我的选项卡式活动布局中。你应该看到我的更新信息上面。谢谢你的回答@我对活动的安排也很好奇,但我迟到了。谢谢你的更新通知。