Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Can';t将相对布局转换为线性布局_Android_Xml_Android Layout_Layout_Android Linearlayout - Fatal编程技术网

Android Can';t将相对布局转换为线性布局

Android Can';t将相对布局转换为线性布局,android,xml,android-layout,layout,android-linearlayout,Android,Xml,Android Layout,Layout,Android Linearlayout,基本上,我用一个已经不推荐使用的库(PercentRelativeLayout)创建了我的所有布局。除了我在ScrollView中有这个布局外,其他一切都很好,而且滚动并不适用于所有设备 我读了一些关于它的话题,似乎问题出在百分比库上 所以我需要继续构建Lienar布局示例,我试图用当前的布局构建我的布局,但是所有的东西都有问题,元素之间的空间与我使用百分比时的空间不同 基本上我需要的是: 元素是自顶向下->工具栏->缩略图->循环视图(这一个只有一个唯一的图像->关于这个foto的详细信息)

基本上,我用一个已经不推荐使用的库(PercentRelativeLayout)创建了我的所有布局。除了我在ScrollView中有这个布局外,其他一切都很好,而且滚动并不适用于所有设备

我读了一些关于它的话题,似乎问题出在百分比库上

所以我需要继续构建Lienar布局示例,我试图用当前的布局构建我的布局,但是所有的东西都有问题,元素之间的空间与我使用百分比时的空间不同

基本上我需要的是:

元素是自顶向下->工具栏->缩略图->循环视图(这一个只有一个唯一的图像->关于这个foto的详细信息)

我有更多关于它的细节,但是如果我能构造这个例子,那就好了

因此,我目前拥有的xml是:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">    

<LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            app:srcCompat="@android:drawable/ic_menu_camera"
            android:elevation="2dp"
            app:layout_widthPercent="90%"
            app:layout_heightPercent="10%"
            app:layout_marginTopPercent="90%"
            app:layout_marginLeftPercent="80%"
            app:backgroundTint="#f1c40f"
            android:onClick="capture"/>

        <include
            layout="@layout/custom_toolbar"
            android:id="@+id/my_toolbar"
            app:layout_widthPercent="100%"
            app:layout_heightPercent="8%"
            app:layout_marginTopPercent="0%"
            app:layout_marginLeftPercent="0%"/>    


        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/SpecieName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/nephritis"
            android:textSize="14dp"
            app:layout_widthPercent="60%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="85%"
            app:layout_marginLeftPercent="30%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/GenreName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="genrePressed"
            android:textColor="@color/nephritis"
            android:textSize="14dp"
            app:layout_widthPercent="60%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="95%"
            app:layout_marginLeftPercent="30%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/FamilyName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="familyPressed"
            android:textColor="@color/nephritis"
            android:textSize="14dp"
            app:layout_widthPercent="60%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="105%"
            app:layout_marginLeftPercent="30%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/textView8"
            android:text="Espécie"
            android:textSize="14dp"
            app:layout_widthPercent="25%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="85%"
            app:layout_marginLeftPercent="5%"
            />

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/textView7"
            app:layout_widthPercent="25%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="95%"
            app:layout_marginLeftPercent="5%"
            android:text="Género"
            android:textSize="14dp" />

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/Family"
            app:layout_widthPercent="25%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="105%"
            app:layout_marginLeftPercent="5%"
            android:text="Familia"
            android:textSize="14dp" />

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/specieDescription"
            android:textSize="14dp"
            app:layout_widthPercent="90%"
            android:layout_height="wrap_content"
            app:layout_marginTopPercent="120%"
            app:layout_marginLeftPercent="5%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/descricaoTit"
            android:text="Descrição"
            android:textSize="14dp"
            app:layout_widthPercent="30%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="115%"
            app:layout_marginLeftPercent="5%"/>

        <ImageView
            android:id="@+id/plantImage"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            app:layout_widthPercent="80%"
            app:layout_heightPercent="50%"
            app:layout_marginTopPercent="12%"
            app:layout_marginLeftPercent="10%"
            app:srcCompat="@drawable/color_cursor_white" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/gallery"
            app:layout_widthPercent="100%"
            app:layout_heightPercent="10%"
            app:layout_marginTopPercent="62%"
            app:layout_marginLeftPercent="0%" />

        <RelativeLayout
            app:layout_widthPercent="40%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="75%"
            app:layout_marginLeftPercent="5%"
            android:onClick="showMap">

            <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
                android:id="@+id/googleMapsText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/imageView6"
                android:layout_alignBottom="@+id/imageView6"
                android:text="Ver no mapa" />

            <ImageView
                android:id="@+id/imageView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_facebook_placeholder_for_locate_places_on_maps"
                android:tint="#F90101" />
        </RelativeLayout>

    </android.support.percent.PercentRelativeLayout>
</LinearLayout>
</ScrollView>

首先要解决您的
滚动视图问题
您必须知道
滚动视图
是有效的,如果您将
线性布局
作为它的子视图,然后在此
线性布局
中剪切所有
视图

请参见此树:

| ScrollView 
|-- LinearLayout
|---- OtherViews you want to scroll 
你想滚动什么并不重要。你必须按照这个方法

编辑:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

               // everything you want to scroll

            </LinearLayout>
         </ScrollView>
</LinearLayout>

//要滚动的所有内容

不是我现在拥有的吗?我用示例代码编辑了我的答案。也许你不能使用
作为所有布局文件的父级。问题是百分比库,我需要减少它,我只是不知道如何实现我的布局,目前我没有百分比相对布局,我的意思是使用线性我什么都不知道关于PerceRelative Layout,但是当android提供创建UI的标准方法时,你可以通过使用普通的
线性布局
+
相对布局
,做任何你想做的事情。为什么你要使用另一个库?因为我很难弄清楚如何根据不同的屏幕大小来调整元素设备,我不想为一个活动创建多个布局