好的,所以我创建了一个ScrollView,里面有两个带元素的线性布局。 当我进入设计模式时,我看到了这个(左图),但是当我在我的手机上运行应用程序时,我得到了这个(右图):
条形图和图片之间的空白区域是我要删除的内容。我不明白它是怎么回事,因为设计视图显示它应该是什么样子。我也使用抽屉菜单。
这是我的xml:
<ScrollView 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"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout 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="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/tvrdjava"
android:id="@+id/imageView8"
android:adjustViewBounds="true"
android:cropToPadding="false" />
<!-- Ovde pocinju kartice (Cards) -->
<LinearLayout
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
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.ivanp.cardivantestdva.MainActivity"
android:orientation="vertical"
android:weightSum="1">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_weight="0.85"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
android:layout_marginBottom="11dp"
card_view:cardBackgroundColor="#607D8B"
android:layout_height="55dp">
<!-- Naslov kartica -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
>
<TextView
android:text="Tvrdjava"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView52"
android:layout_weight="1"
android:textSize="20sp"
android:textColor="@android:color/white"
/>
<TextView
android:text="test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/datumprikaz"
android:layout_weight="1"
android:textSize="20sp"
android:textColor="@android:color/white"
android:gravity="right"
/>
</LinearLayout>
<View
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/textView9"
android:layout_marginTop="38dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@android:color/white" />
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</ScrollView>
更新:这是我的活动主要xml
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
/>
这是我的activity_main_drawer:
<?xml version="1.0" encoding="utf-8"?>
<group android:checkableBehavior="single"
android:id="@+id/menu_top">
<item
android:id="@+id/nav_tvrdjava"
android:icon="@drawable/ic_menu_camera"
android:title="Tvrdjava" />
<item
android:id="@+id/nav_bubanj"
android:icon="@drawable/ic_menu_gallery"
android:title="Bubanj" />
<item
android:id="@+id/nav_cegar"
android:icon="@drawable/ic_menu_slideshow"
android:title="Čegar" />
<item
android:id="@+id/nav_celekula"
android:icon="@drawable/ic_menu_manage"
android:title="Ćele kula" />
</group>
<group
android:id="@+id/menu_bottom"
android:checkableBehavior="single">
<item
android:id="@+id/nav_podesavanja"
android:icon="@drawable/ic_menu_share"
android:title="Podešavanja" />
<item
android:id="@+id/nav_onama"
android:icon="@drawable/ic_menu_send"
android:title="O Nama" />
</group>
答案 0 :(得分:0)
修正了它! 问题是values / dimens.xml中的默认边距 刚改变了这个:
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="nav_header_vertical_spacing">16dp</dimen>
<dimen name="nav_header_height">160dp</dimen>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
对此:
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="nav_header_vertical_spacing">16dp</dimen>
<dimen name="nav_header_height">160dp</dimen>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>
<dimen name="fab_margin">16dp</dimen>