我在Android Studio上查看布局时遇到了问题。

huangapple go评论76阅读模式
英文:

I have a problem viewing the layout on Android Studio

问题

我会尽量简洁。

在某些设备上启动我的应用程序时,我遇到了CardView排列的问题。
我认为这在旧设备上发生了。下面我添加了图片,在前两张图片中不存在问题,在另外两张图片中存在问题。

我已尝试了一切,在Android Studio中,所有API(20-29)都显示正确,Java代码没有更改。

三星j5 2016年:
我在Android Studio上查看布局时遇到了问题。

小米红米5 Plus:
我在Android Studio上查看布局时遇到了问题。

联想平板电脑:
我在Android Studio上查看布局时遇到了问题。

Wiko彩虹lite:
我在Android Studio上查看布局时遇到了问题。

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/dracula"
    tools:context=".Capitoli">

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

        <RelativeLayout
            android:layout_marginTop="32dp"
            android:layout_marginRight="20dp"
            android:layout_marginLeft="20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/text"
                android:text="hi"
                android:textSize="24sp"
                android:textColor="#FFF"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

            <TextView
                android:layout_marginTop="6dp"
                android:layout_below="@+id/text"
                android:text="58 "
                android:textSize="14sp"
                android:textColor="#FFF"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

            <ImageView
                android:layout_alignParentRight="true"
                android:layout_width="62dp"
                android:layout_height="62dp"
                android:src="@drawable/tomato"/>

        </RelativeLayout>

        <GridLayout
            android:columnCount="2"
            android:rowCount="3"
            android:alignmentMode="alignMargins"
            android:columnOrderPreserved="false"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <androidx.cardview.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_columnWeight="1"
                android:layout_rowWeight="1"
                app:cardElevation="6dp"
                app:cardCornerRadius="12dp"
                android:layout_margin="12dp">

                <LinearLayout
                    android:orientation="vertical"
                    android:padding="16dp"
                    android:gravity="center"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <ImageView
                        android:src="@drawable/whale"
                        android:layout_width="80dp"
                        android:layout_height="80dp"/>

                    <TextView
                        android:textColor="@color/viola"
                        android:textSize="18sp"
                        android:text="capitolo 1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>

                </LinearLayout>

            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_columnWeight="1"
                android:layout_rowWeight="1"
                app:cardElevation="6dp"
                app:cardCornerRadius="12dp"
                android:layout_margin="12dp">
                <LinearLayout
                    android:orientation="vertical"
                    android:padding="16dp"
                    android:gravity="center"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <ImageView
                        android:src="@drawable/whale"
                        android:layout_width="80dp"
                        android:layout_height="80dp"/>

                    <TextView
                        android:textColor="@color/viola"
                        android:textSize="18sp"
                        android:text="capitolo 1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>

                </LinearLayout>

            </androidx.cardview.widget.CardView>

        </GridLayout>

    </LinearLayout>

</ScrollView>
英文:

I'll try to be brief.
When I start my app on some devices I have problems in the arrangement of the CardView.
I think this happens with older devices. I add below the images, in the first two the problem does not exist, in the other two yes.

I tried everything, in Android studio it shows correctly with all the APIs (20-29)
the java code has not been changed.

Samsung j5 2016:
我在Android Studio上查看布局时遇到了问题。

Xiaomi Redmi 5 Plus:
我在Android Studio上查看布局时遇到了问题。

Tablet Lenovo:
我在Android Studio上查看布局时遇到了问题。

Wiko Rainbow lite:
我在Android Studio上查看布局时遇到了问题。

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;ScrollView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:background=&quot;@color/dracula&quot;
tools:context=&quot;.Capitoli&quot;&gt;
&lt;LinearLayout
android:orientation=&quot;vertical&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;&gt;
&lt;RelativeLayout
android:layout_marginTop=&quot;32dp&quot;
android:layout_marginRight=&quot;20dp&quot;
android:layout_marginLeft=&quot;20dp&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;&gt;
&lt;TextView
android:id=&quot;@+id/text&quot;
android:text=&quot;hi&quot;
android:textSize=&quot;24sp&quot;
android:textColor=&quot;#FFF&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;/&gt;
&lt;TextView
android:layout_marginTop=&quot;6dp&quot;
android:layout_below=&quot;@+id/text&quot;
android:text=&quot;58 &quot;
android:textSize=&quot;14sp&quot;
android:textColor=&quot;#FFF&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;/&gt;
&lt;ImageView
android:layout_alignParentRight=&quot;true&quot;
android:layout_width=&quot;62dp&quot;
android:layout_height=&quot;62dp&quot;
android:src=&quot;@drawable/tomato&quot;/&gt;
&lt;/RelativeLayout&gt;
&lt;GridLayout
android:columnCount=&quot;2&quot;
android:rowCount=&quot;3&quot;
android:alignmentMode=&quot;alignMargins&quot;
android:columnOrderPreserved=&quot;false&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;&gt;
&lt;androidx.cardview.widget.CardView
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_columnWeight=&quot;1&quot;
android:layout_rowWeight=&quot;1&quot;
app:cardElevation=&quot;6dp&quot;
app:cardCornerRadius=&quot;12dp&quot;
android:layout_margin=&quot;12dp&quot;&gt;
&lt;LinearLayout
android:orientation=&quot;vertical&quot;
android:padding=&quot;16dp&quot;
android:gravity=&quot;center&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;&gt;
&lt;ImageView
android:src=&quot;@drawable/whale&quot;
android:layout_width=&quot;80dp&quot;
android:layout_height=&quot;80dp&quot;/&gt;
&lt;TextView
android:textColor=&quot;@color/viola&quot;
android:textSize=&quot;18sp&quot;
android:text=&quot;capitolo 1&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;/&gt;
&lt;/LinearLayout&gt;
&lt;/androidx.cardview.widget.CardView&gt;
&lt;androidx.cardview.widget.CardView
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_columnWeight=&quot;1&quot;
android:layout_rowWeight=&quot;1&quot;
app:cardElevation=&quot;6dp&quot;
app:cardCornerRadius=&quot;12dp&quot;
android:layout_margin=&quot;12dp&quot;&gt;
&lt;LinearLayout
android:orientation=&quot;vertical&quot;
android:padding=&quot;16dp&quot;
android:gravity=&quot;center&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;&gt;
&lt;ImageView
android:src=&quot;@drawable/whale&quot;
android:layout_width=&quot;80dp&quot;
android:layout_height=&quot;80dp&quot;/&gt;
&lt;TextView
android:textColor=&quot;@color/viola&quot;
android:textSize=&quot;18sp&quot;
android:text=&quot;capitolo 1&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;/&gt;
&lt;/LinearLayout&gt;
&lt;/androidx.cardview.widget.CardView&gt;
&lt;/GridLayout&gt;
&lt;/LinearLayout&gt;
&lt;/ScrollView&gt;

答案1

得分: 0

以下是代码的翻译部分:

<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"
    android:background="@android:color/black"
    tools:context=".Capitoli">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="32dp"
            android:layout_marginRight="20dp">

            <TextView
                android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="hi"
                android:textColor="#FFF"
                android:textSize="24sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/text"
                android:layout_marginTop="6dp"
                android:text="58 "
                android:textColor="#FFF"
                android:textSize="14sp" />

            <ImageView
                android:layout_width="62dp"
                android:layout_height="62dp"
                android:layout_alignParentRight="true"
                android:src="@drawable/ic_launcher" />

        </RelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:weightSum="2"
            android:layout_height="wrap_content">

            <androidx.cardview.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="12dp"
                android:layout_weight="1"
                app:cardCornerRadius="12dp"
                app:cardElevation="6dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:padding="16dp">

                    <ImageView
                        android:layout_width="80dp"
                        android:layout_height="80dp"
                        android:src="@drawable/whale" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="capitolo 1"
                        android:textColor="@color/viola"
                        android:textSize="18sp" />

                </LinearLayout>

            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="12dp"
                android:layout_weight="1"
                app:cardCornerRadius="12dp"
                app:cardElevation="6dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:padding="16dp">

                    <ImageView
                        android:layout_width="80dp"
                        android:layout_height="80dp"
                        android:src="@drawable/whale" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="capitolo 1"
                        android:textColor="@color/viola"
                        android:textSize="18sp" />

                </LinearLayout>

            </androidx.cardview.widget.CardView>
        </LinearLayout>
    </LinearLayout>
</ScrollView>

希望这对您有帮助。如果您需要进一步的翻译或帮助,请告诉我。

英文:

Hi Please try with following code. I have updated it. please try with this

&lt;ScrollView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:background=&quot;@android:color/black&quot;
tools:context=&quot;.Capitoli&quot;&gt;
&lt;LinearLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:orientation=&quot;vertical&quot;&gt;
&lt;RelativeLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginLeft=&quot;20dp&quot;
android:layout_marginTop=&quot;32dp&quot;
android:layout_marginRight=&quot;20dp&quot;&gt;
&lt;TextView
android:id=&quot;@+id/text&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;hi&quot;
android:textColor=&quot;#FFF&quot;
android:textSize=&quot;24sp&quot; /&gt;
&lt;TextView
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_below=&quot;@+id/text&quot;
android:layout_marginTop=&quot;6dp&quot;
android:text=&quot;58 &quot;
android:textColor=&quot;#FFF&quot;
android:textSize=&quot;14sp&quot; /&gt;
&lt;ImageView
android:layout_width=&quot;62dp&quot;
android:layout_height=&quot;62dp&quot;
android:layout_alignParentRight=&quot;true&quot;
android:src=&quot;@drawable/ic_launcher&quot; /&gt;
&lt;/RelativeLayout&gt;
&lt;LinearLayout
android:layout_width=&quot;match_parent&quot;
android:orientation=&quot;horizontal&quot;
android:weightSum=&quot;2&quot;
android:layout_height=&quot;wrap_content&quot;&gt;
&lt;androidx.cardview.widget.CardView
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_margin=&quot;12dp&quot;
android:layout_weight=&quot;1&quot;
app:cardCornerRadius=&quot;12dp&quot;
app:cardElevation=&quot;6dp&quot;&gt;
&lt;LinearLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:gravity=&quot;center&quot;
android:orientation=&quot;vertical&quot;
android:padding=&quot;16dp&quot;&gt;
&lt;ImageView
android:layout_width=&quot;80dp&quot;
android:layout_height=&quot;80dp&quot;
android:src=&quot;@drawable/whale&quot; /&gt;
&lt;TextView
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;capitolo 1&quot;
android:textColor=&quot;@color/viola&quot;
android:textSize=&quot;18sp&quot; /&gt;
&lt;/LinearLayout&gt;
&lt;/androidx.cardview.widget.CardView&gt;
&lt;androidx.cardview.widget.CardView
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_margin=&quot;12dp&quot;
android:layout_weight=&quot;1&quot;
app:cardCornerRadius=&quot;12dp&quot;
app:cardElevation=&quot;6dp&quot;&gt;
&lt;LinearLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:gravity=&quot;center&quot;
android:orientation=&quot;vertical&quot;
android:padding=&quot;16dp&quot;&gt;
&lt;ImageView
android:layout_width=&quot;80dp&quot;
android:layout_height=&quot;80dp&quot;
android:src=&quot;@drawable/whale&quot; /&gt;
&lt;TextView
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;capitolo 1&quot;
android:textColor=&quot;@color/viola&quot;
android:textSize=&quot;18sp&quot; /&gt;
&lt;/LinearLayout&gt;
&lt;/androidx.cardview.widget.CardView&gt;
&lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;
&lt;/ScrollView&gt;

huangapple
  • 本文由 发表于 2020年1月6日 19:00:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/59610897.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定