我正在尝试为一个学校项目编写一个应用程序。我被设计卡住了。我在手机上看不到我的右侧活动,但它显示在Android Studio预览中。可能是我的代码不正确,或者我没有尊重某些东西。
下面是两个截图: Android Studio预览:https://pasteboard.co/I6uT89f.png
电话视图:https://pasteboard.co/I6uSgpW.jpg
代码如下:
activity_main.xml
<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:background="@color/colorPrimaryDark"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
</android.support.design.widget.AppBarLayout>
<include
android:id="@+id/include"
layout="@layout/content_main" />
<com.leinardi.android.speeddial.SpeedDialOverlayLayout
android:id="@+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="#131313"/>
<com.leinardi.android.speeddial.SpeedDialView
android:id="@+id/speedDial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:sdMainFabClosedSrc="@drawable/ic_menu"
app:sdOverlayLayout="@id/overlay"/>
</android.support.design.widget.CoordinatorLayout>
content_main.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="340dp"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/header2"
android:scaleType="fitCenter"
android:layout_marginTop="-20dp"/>
</RelativeLayout>
<RelativeLayout
android:clickable="true"
android:focusable="true"
android:id="@+id/plante1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:background="@drawable/ripple"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="-10dp"
android:layout_marginBottom="15dp"
android:gravity="center">
<RelativeLayout
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="10dp"
android:background="@drawable/logo_shape">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<fr.visufo.titouan.jardin.UnderlinedTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="0dp"
android:gravity="left"
android:text="Plante 1"
android:textSize="20dp"
android:fontFamily="@font/raleway_light"
android:textColor="#000000"
app:underlineColor="#6DB85C"
app:underlineWidth="10px"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="80dp"
android:layout_marginTop="30dp"
android:textSize="15dp"
android:textColor="#000000"
android:text="Pensez à rentrer votre plante demain"
android:fontFamily="@font/raleway_light"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="335dp"
android:layout_marginRight="7dp"
android:layout_marginTop="-4dp"
android:background="@drawable/degrees_shape">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="0°C"
android:gravity="center"
android:fontFamily="@font/roboto"
android:textSize="18dp"
android:textColor="#636363"/>
</RelativeLayout>
</RelativeLayout>
There are 8 similar relative layouts showing quite the same thing, here's
only one
</LinearLayout>
</ScrollView>
发布于 2019-03-22 07:32:33
@titouan-pellerin -不像在网站设计中那样使用div
作为(大多数)东西的容器,你不需要重复地将每个单独的视图包装在它自己的布局中。
例如,如果我想让我的活动垂直显示如下所示:
(标题)
(一些较小的潜台词)
(一个图像)
(一些描述文本)
(和底部的两个按钮)
..I不会将这些东西分别包装在各自的布局中--我会简单地创建1基本布局(作为主容器),然后在它内部,我将为内容创建1垂直布局(垂直排列),并为底部的按钮创建1水平布局(水平排列)。
当然,你也需要根据你想要的显示方式来设置你的边距。
你最有可能遇到的问题是,由于边距一次又一次地叠加在一起,并扩展到屏幕边界之外,再加上手机的像素密度和分辨率可能与模拟器不同。
第1步:修复您的布局,如上所述。
第2步:选择/设置与您的设备分辨率/像素密度最匹配的仿真器。
希望这能有所帮助!
如果你觉得这是一个很好的解释,请接受这作为你的问题的答案。
谢谢,祝你编码愉快!
https://stackoverflow.com/questions/55289339
复制相似问题