【问题标题】:How to remove the gaps on my toolbar without changing the layout of my listview如何在不更改列表视图布局的情况下删除工具栏上的空白
【发布时间】:2018-03-31 03:54:10
【问题描述】:

我正在创建一个工具栏。我已经准备好了所有东西,但是我无法摆脱两边以及顶部出现的缝隙。它似乎在模仿它下面的列表视图的间隙。我知道我可以删除相对布局中的填充属性。问题是,当我这样做时,列表视图的布局(位于工具栏的底部)会随之变化,我希望它保持原样。有没有人对如何在保持我的其余活动布局的同时消除那些不需要的间隙有什么建议?

这是我的 xml 布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    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="com.example.jesse.myapp.FavoriteActivity">


    <include
        layout="@layout/favoritebar"
        android:id="@+id/fb"/>     

    <ListView
        android:id="@+id/languageselector"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="50dp"
        android:clickable="false" />

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


    <TextView
        android:id="@+id/emptyElement"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="NO FAVORITES AVAILABLE"
        android:textColor="#525252"
        android:textSize="19.0sp"
        android:visibility="gone" />

    <Button
        android:id="@+id/checklist"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@mipmap/arrow2"
        android:gravity="end"
        android:text=""/>    

</RelativeLayout>

以及工具栏的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:theme= "@style/Toolbarstyle">
</android.support.v7.widget.Toolbar>

【问题讨论】:

  • 请不要重复您的问题
  • 这不是我的问题的重复
  • 请不要重复提问。只需使用您拥有的任何新信息、您尝试过的任何新代码或任何已发布答案不起作用的解释来编辑您的原始帖子,就会将它推到活动队列的顶部。
  • @Fgf567 分享您的 favoritebar 布局代码
  • Lolz,这是一个不同的问题。你认为我应该保留原来的帖子,其中的答案与问题无关?

标签: java android xml android-layout android-toolbar


【解决方案1】:

如果您想要相对布局内容,这应该可以工作:

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

<include
    layout="@layout/favoritebar"
    android:id="@+id/fb"/>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    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="com.example.jesse.myapp.FavoriteActivity">

    <ListView
        android:id="@+id/languageselector"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="50dp"
        android:clickable="false" />

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


    <TextView
        android:id="@+id/emptyElement"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="NO FAVORITES AVAILABLE"
        android:textColor="#525252"
        android:textSize="19.0sp"
        android:visibility="gone" />

    <Button
        android:id="@+id/checklist"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@mipmap/arrow2"
        android:gravity="end"
        android:text=""/>

</RelativeLayout>

</LinearLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-22
    • 1970-01-01
    相关资源
    最近更新 更多