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

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

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上查看布局时遇到了问题。

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:background="@color/dracula"
  8. tools:context=".Capitoli">
  9. <LinearLayout
  10. android:orientation="vertical"
  11. android:layout_width="match_parent"
  12. android:layout_height="match_parent">
  13. <RelativeLayout
  14. android:layout_marginTop="32dp"
  15. android:layout_marginRight="20dp"
  16. android:layout_marginLeft="20dp"
  17. android:layout_width="match_parent"
  18. android:layout_height="wrap_content">
  19. <TextView
  20. android:id="@+id/text"
  21. android:text="hi"
  22. android:textSize="24sp"
  23. android:textColor="#FFF"
  24. android:layout_width="wrap_content"
  25. android:layout_height="wrap_content"/>
  26. <TextView
  27. android:layout_marginTop="6dp"
  28. android:layout_below="@+id/text"
  29. android:text="58 "
  30. android:textSize="14sp"
  31. android:textColor="#FFF"
  32. android:layout_width="wrap_content"
  33. android:layout_height="wrap_content"/>
  34. <ImageView
  35. android:layout_alignParentRight="true"
  36. android:layout_width="62dp"
  37. android:layout_height="62dp"
  38. android:src="@drawable/tomato"/>
  39. </RelativeLayout>
  40. <GridLayout
  41. android:columnCount="2"
  42. android:rowCount="3"
  43. android:alignmentMode="alignMargins"
  44. android:columnOrderPreserved="false"
  45. android:layout_width="match_parent"
  46. android:layout_height="wrap_content">
  47. <androidx.cardview.widget.CardView
  48. android:layout_width="wrap_content"
  49. android:layout_height="wrap_content"
  50. android:layout_columnWeight="1"
  51. android:layout_rowWeight="1"
  52. app:cardElevation="6dp"
  53. app:cardCornerRadius="12dp"
  54. android:layout_margin="12dp">
  55. <LinearLayout
  56. android:orientation="vertical"
  57. android:padding="16dp"
  58. android:gravity="center"
  59. android:layout_width="match_parent"
  60. android:layout_height="match_parent">
  61. <ImageView
  62. android:src="@drawable/whale"
  63. android:layout_width="80dp"
  64. android:layout_height="80dp"/>
  65. <TextView
  66. android:textColor="@color/viola"
  67. android:textSize="18sp"
  68. android:text="capitolo 1"
  69. android:layout_width="wrap_content"
  70. android:layout_height="wrap_content"/>
  71. </LinearLayout>
  72. </androidx.cardview.widget.CardView>
  73. <androidx.cardview.widget.CardView
  74. android:layout_width="wrap_content"
  75. android:layout_height="wrap_content"
  76. android:layout_columnWeight="1"
  77. android:layout_rowWeight="1"
  78. app:cardElevation="6dp"
  79. app:cardCornerRadius="12dp"
  80. android:layout_margin="12dp">
  81. <LinearLayout
  82. android:orientation="vertical"
  83. android:padding="16dp"
  84. android:gravity="center"
  85. android:layout_width="match_parent"
  86. android:layout_height="match_parent">
  87. <ImageView
  88. android:src="@drawable/whale"
  89. android:layout_width="80dp"
  90. android:layout_height="80dp"/>
  91. <TextView
  92. android:textColor="@color/viola"
  93. android:textSize="18sp"
  94. android:text="capitolo 1"
  95. android:layout_width="wrap_content"
  96. android:layout_height="wrap_content"/>
  97. </LinearLayout>
  98. </androidx.cardview.widget.CardView>
  99. </GridLayout>
  100. </LinearLayout>
  101. </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上查看布局时遇到了问题。

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  2. &lt;ScrollView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  3. xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  4. xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  5. android:layout_width=&quot;match_parent&quot;
  6. android:layout_height=&quot;match_parent&quot;
  7. android:background=&quot;@color/dracula&quot;
  8. tools:context=&quot;.Capitoli&quot;&gt;
  9. &lt;LinearLayout
  10. android:orientation=&quot;vertical&quot;
  11. android:layout_width=&quot;match_parent&quot;
  12. android:layout_height=&quot;match_parent&quot;&gt;
  13. &lt;RelativeLayout
  14. android:layout_marginTop=&quot;32dp&quot;
  15. android:layout_marginRight=&quot;20dp&quot;
  16. android:layout_marginLeft=&quot;20dp&quot;
  17. android:layout_width=&quot;match_parent&quot;
  18. android:layout_height=&quot;wrap_content&quot;&gt;
  19. &lt;TextView
  20. android:id=&quot;@+id/text&quot;
  21. android:text=&quot;hi&quot;
  22. android:textSize=&quot;24sp&quot;
  23. android:textColor=&quot;#FFF&quot;
  24. android:layout_width=&quot;wrap_content&quot;
  25. android:layout_height=&quot;wrap_content&quot;/&gt;
  26. &lt;TextView
  27. android:layout_marginTop=&quot;6dp&quot;
  28. android:layout_below=&quot;@+id/text&quot;
  29. android:text=&quot;58 &quot;
  30. android:textSize=&quot;14sp&quot;
  31. android:textColor=&quot;#FFF&quot;
  32. android:layout_width=&quot;wrap_content&quot;
  33. android:layout_height=&quot;wrap_content&quot;/&gt;
  34. &lt;ImageView
  35. android:layout_alignParentRight=&quot;true&quot;
  36. android:layout_width=&quot;62dp&quot;
  37. android:layout_height=&quot;62dp&quot;
  38. android:src=&quot;@drawable/tomato&quot;/&gt;
  39. &lt;/RelativeLayout&gt;
  40. &lt;GridLayout
  41. android:columnCount=&quot;2&quot;
  42. android:rowCount=&quot;3&quot;
  43. android:alignmentMode=&quot;alignMargins&quot;
  44. android:columnOrderPreserved=&quot;false&quot;
  45. android:layout_width=&quot;match_parent&quot;
  46. android:layout_height=&quot;wrap_content&quot;&gt;
  47. &lt;androidx.cardview.widget.CardView
  48. android:layout_width=&quot;wrap_content&quot;
  49. android:layout_height=&quot;wrap_content&quot;
  50. android:layout_columnWeight=&quot;1&quot;
  51. android:layout_rowWeight=&quot;1&quot;
  52. app:cardElevation=&quot;6dp&quot;
  53. app:cardCornerRadius=&quot;12dp&quot;
  54. android:layout_margin=&quot;12dp&quot;&gt;
  55. &lt;LinearLayout
  56. android:orientation=&quot;vertical&quot;
  57. android:padding=&quot;16dp&quot;
  58. android:gravity=&quot;center&quot;
  59. android:layout_width=&quot;match_parent&quot;
  60. android:layout_height=&quot;match_parent&quot;&gt;
  61. &lt;ImageView
  62. android:src=&quot;@drawable/whale&quot;
  63. android:layout_width=&quot;80dp&quot;
  64. android:layout_height=&quot;80dp&quot;/&gt;
  65. &lt;TextView
  66. android:textColor=&quot;@color/viola&quot;
  67. android:textSize=&quot;18sp&quot;
  68. android:text=&quot;capitolo 1&quot;
  69. android:layout_width=&quot;wrap_content&quot;
  70. android:layout_height=&quot;wrap_content&quot;/&gt;
  71. &lt;/LinearLayout&gt;
  72. &lt;/androidx.cardview.widget.CardView&gt;
  73. &lt;androidx.cardview.widget.CardView
  74. android:layout_width=&quot;wrap_content&quot;
  75. android:layout_height=&quot;wrap_content&quot;
  76. android:layout_columnWeight=&quot;1&quot;
  77. android:layout_rowWeight=&quot;1&quot;
  78. app:cardElevation=&quot;6dp&quot;
  79. app:cardCornerRadius=&quot;12dp&quot;
  80. android:layout_margin=&quot;12dp&quot;&gt;
  81. &lt;LinearLayout
  82. android:orientation=&quot;vertical&quot;
  83. android:padding=&quot;16dp&quot;
  84. android:gravity=&quot;center&quot;
  85. android:layout_width=&quot;match_parent&quot;
  86. android:layout_height=&quot;match_parent&quot;&gt;
  87. &lt;ImageView
  88. android:src=&quot;@drawable/whale&quot;
  89. android:layout_width=&quot;80dp&quot;
  90. android:layout_height=&quot;80dp&quot;/&gt;
  91. &lt;TextView
  92. android:textColor=&quot;@color/viola&quot;
  93. android:textSize=&quot;18sp&quot;
  94. android:text=&quot;capitolo 1&quot;
  95. android:layout_width=&quot;wrap_content&quot;
  96. android:layout_height=&quot;wrap_content&quot;/&gt;
  97. &lt;/LinearLayout&gt;
  98. &lt;/androidx.cardview.widget.CardView&gt;
  99. &lt;/GridLayout&gt;
  100. &lt;/LinearLayout&gt;
  101. &lt;/ScrollView&gt;

答案1

得分: 0

以下是代码的翻译部分:

  1. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:app="http://schemas.android.com/apk/res-auto"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:background="@android:color/black"
  7. tools:context=".Capitoli">
  8. <LinearLayout
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:orientation="vertical">
  12. <RelativeLayout
  13. android:layout_width="match_parent"
  14. android:layout_height="wrap_content"
  15. android:layout_marginLeft="20dp"
  16. android:layout_marginTop="32dp"
  17. android:layout_marginRight="20dp">
  18. <TextView
  19. android:id="@+id/text"
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:text="hi"
  23. android:textColor="#FFF"
  24. android:textSize="24sp" />
  25. <TextView
  26. android:layout_width="wrap_content"
  27. android:layout_height="wrap_content"
  28. android:layout_below="@+id/text"
  29. android:layout_marginTop="6dp"
  30. android:text="58 "
  31. android:textColor="#FFF"
  32. android:textSize="14sp" />
  33. <ImageView
  34. android:layout_width="62dp"
  35. android:layout_height="62dp"
  36. android:layout_alignParentRight="true"
  37. android:src="@drawable/ic_launcher" />
  38. </RelativeLayout>
  39. <LinearLayout
  40. android:layout_width="match_parent"
  41. android:orientation="horizontal"
  42. android:weightSum="2"
  43. android:layout_height="wrap_content">
  44. <androidx.cardview.widget.CardView
  45. android:layout_width="wrap_content"
  46. android:layout_height="wrap_content"
  47. android:layout_margin="12dp"
  48. android:layout_weight="1"
  49. app:cardCornerRadius="12dp"
  50. app:cardElevation="6dp">
  51. <LinearLayout
  52. android:layout_width="match_parent"
  53. android:layout_height="match_parent"
  54. android:gravity="center"
  55. android:orientation="vertical"
  56. android:padding="16dp">
  57. <ImageView
  58. android:layout_width="80dp"
  59. android:layout_height="80dp"
  60. android:src="@drawable/whale" />
  61. <TextView
  62. android:layout_width="wrap_content"
  63. android:layout_height="wrap_content"
  64. android:text="capitolo 1"
  65. android:textColor="@color/viola"
  66. android:textSize="18sp" />
  67. </LinearLayout>
  68. </androidx.cardview.widget.CardView>
  69. <androidx.cardview.widget.CardView
  70. android:layout_width="wrap_content"
  71. android:layout_height="wrap_content"
  72. android:layout_margin="12dp"
  73. android:layout_weight="1"
  74. app:cardCornerRadius="12dp"
  75. app:cardElevation="6dp">
  76. <LinearLayout
  77. android:layout_width="match_parent"
  78. android:layout_height="match_parent"
  79. android:gravity="center"
  80. android:orientation="vertical"
  81. android:padding="16dp">
  82. <ImageView
  83. android:layout_width="80dp"
  84. android:layout_height="80dp"
  85. android:src="@drawable/whale" />
  86. <TextView
  87. android:layout_width="wrap_content"
  88. android:layout_height="wrap_content"
  89. android:text="capitolo 1"
  90. android:textColor="@color/viola"
  91. android:textSize="18sp" />
  92. </LinearLayout>
  93. </androidx.cardview.widget.CardView>
  94. </LinearLayout>
  95. </LinearLayout>
  96. </ScrollView>

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

英文:

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

  1. &lt;ScrollView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  2. xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  3. xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  4. android:layout_width=&quot;match_parent&quot;
  5. android:layout_height=&quot;match_parent&quot;
  6. android:background=&quot;@android:color/black&quot;
  7. tools:context=&quot;.Capitoli&quot;&gt;
  8. &lt;LinearLayout
  9. android:layout_width=&quot;match_parent&quot;
  10. android:layout_height=&quot;match_parent&quot;
  11. android:orientation=&quot;vertical&quot;&gt;
  12. &lt;RelativeLayout
  13. android:layout_width=&quot;match_parent&quot;
  14. android:layout_height=&quot;wrap_content&quot;
  15. android:layout_marginLeft=&quot;20dp&quot;
  16. android:layout_marginTop=&quot;32dp&quot;
  17. android:layout_marginRight=&quot;20dp&quot;&gt;
  18. &lt;TextView
  19. android:id=&quot;@+id/text&quot;
  20. android:layout_width=&quot;wrap_content&quot;
  21. android:layout_height=&quot;wrap_content&quot;
  22. android:text=&quot;hi&quot;
  23. android:textColor=&quot;#FFF&quot;
  24. android:textSize=&quot;24sp&quot; /&gt;
  25. &lt;TextView
  26. android:layout_width=&quot;wrap_content&quot;
  27. android:layout_height=&quot;wrap_content&quot;
  28. android:layout_below=&quot;@+id/text&quot;
  29. android:layout_marginTop=&quot;6dp&quot;
  30. android:text=&quot;58 &quot;
  31. android:textColor=&quot;#FFF&quot;
  32. android:textSize=&quot;14sp&quot; /&gt;
  33. &lt;ImageView
  34. android:layout_width=&quot;62dp&quot;
  35. android:layout_height=&quot;62dp&quot;
  36. android:layout_alignParentRight=&quot;true&quot;
  37. android:src=&quot;@drawable/ic_launcher&quot; /&gt;
  38. &lt;/RelativeLayout&gt;
  39. &lt;LinearLayout
  40. android:layout_width=&quot;match_parent&quot;
  41. android:orientation=&quot;horizontal&quot;
  42. android:weightSum=&quot;2&quot;
  43. android:layout_height=&quot;wrap_content&quot;&gt;
  44. &lt;androidx.cardview.widget.CardView
  45. android:layout_width=&quot;wrap_content&quot;
  46. android:layout_height=&quot;wrap_content&quot;
  47. android:layout_margin=&quot;12dp&quot;
  48. android:layout_weight=&quot;1&quot;
  49. app:cardCornerRadius=&quot;12dp&quot;
  50. app:cardElevation=&quot;6dp&quot;&gt;
  51. &lt;LinearLayout
  52. android:layout_width=&quot;match_parent&quot;
  53. android:layout_height=&quot;match_parent&quot;
  54. android:gravity=&quot;center&quot;
  55. android:orientation=&quot;vertical&quot;
  56. android:padding=&quot;16dp&quot;&gt;
  57. &lt;ImageView
  58. android:layout_width=&quot;80dp&quot;
  59. android:layout_height=&quot;80dp&quot;
  60. android:src=&quot;@drawable/whale&quot; /&gt;
  61. &lt;TextView
  62. android:layout_width=&quot;wrap_content&quot;
  63. android:layout_height=&quot;wrap_content&quot;
  64. android:text=&quot;capitolo 1&quot;
  65. android:textColor=&quot;@color/viola&quot;
  66. android:textSize=&quot;18sp&quot; /&gt;
  67. &lt;/LinearLayout&gt;
  68. &lt;/androidx.cardview.widget.CardView&gt;
  69. &lt;androidx.cardview.widget.CardView
  70. android:layout_width=&quot;wrap_content&quot;
  71. android:layout_height=&quot;wrap_content&quot;
  72. android:layout_margin=&quot;12dp&quot;
  73. android:layout_weight=&quot;1&quot;
  74. app:cardCornerRadius=&quot;12dp&quot;
  75. app:cardElevation=&quot;6dp&quot;&gt;
  76. &lt;LinearLayout
  77. android:layout_width=&quot;match_parent&quot;
  78. android:layout_height=&quot;match_parent&quot;
  79. android:gravity=&quot;center&quot;
  80. android:orientation=&quot;vertical&quot;
  81. android:padding=&quot;16dp&quot;&gt;
  82. &lt;ImageView
  83. android:layout_width=&quot;80dp&quot;
  84. android:layout_height=&quot;80dp&quot;
  85. android:src=&quot;@drawable/whale&quot; /&gt;
  86. &lt;TextView
  87. android:layout_width=&quot;wrap_content&quot;
  88. android:layout_height=&quot;wrap_content&quot;
  89. android:text=&quot;capitolo 1&quot;
  90. android:textColor=&quot;@color/viola&quot;
  91. android:textSize=&quot;18sp&quot; /&gt;
  92. &lt;/LinearLayout&gt;
  93. &lt;/androidx.cardview.widget.CardView&gt;
  94. &lt;/LinearLayout&gt;
  95. &lt;/LinearLayout&gt;
  96. &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:

确定