Android: 滚动视图中的线性布局未显示
Android: Linear layout inside scrollview is not showing
滚动视图中也有一些线性布局。
当我在 HUAWEI Mate7 上安装该应用程序时,它工作正常。
但在三星 S3 或 LG G3 上,唯一显示的是背景图像,但当我触摸屏幕时,方法正在运行。只有视图没有显示。
这里是 mainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back1"
android:alpha=".9">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha=".9"
android:gravity="center">
</LinearLayout>
</ScrollView>
</RelativeLayout>
线性布局里面有 20 个这样
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp" >
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="@+id/imageButton7"
android:src="@drawable/can_pot_com"
android:scaleType="fitStart"
android:background="#00ffffff"
android:cropToPadding="false"
android:foregroundGravity="bottom"
android:layout_weight="2" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/can_pot"
android:id="@+id/button6"
android:textStyle="bold"
android:textIsSelectable="false"
android:lines="3"
android:linksClickable="false"
android:textColor="#000000"
android:background="#00ffffff"
android:layout_weight="3" />
</LinearLayout>
不知道怎么办!
从滚动视图中删除这一行
xmlns:android="http://schemas.android.com/apk/res/android"
问题可能与布局的对齐和引力有关;在 ScrollView 内的 LinearLayout 子项中,将 android:gravity="center
更改为:android:gravity="top|center"
。希望对你有帮助。
(虽然它不会给你一个错误,你可以删除第二个 xmlns:android="http://schemas.android.com/apk/res/android")
试试这个代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back1"
android:alpha=".9"> <ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha=".9"
android:gravity="center">
</LinearLayout>
</ScrollView>
我遇到了类似的问题。我的 ScrollView 中的 LinearLayout 没有按预期工作。 lineaLayout 的第一个组件不可见。
原因是android:layout_gravity="center_vertical"。将其更改为 android:layout_gravity="top|center_vertical".
滚动视图中也有一些线性布局。 当我在 HUAWEI Mate7 上安装该应用程序时,它工作正常。 但在三星 S3 或 LG G3 上,唯一显示的是背景图像,但当我触摸屏幕时,方法正在运行。只有视图没有显示。 这里是 mainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back1"
android:alpha=".9">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha=".9"
android:gravity="center">
</LinearLayout>
</ScrollView>
</RelativeLayout>
线性布局里面有 20 个这样
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp" >
<ImageButton
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="@+id/imageButton7"
android:src="@drawable/can_pot_com"
android:scaleType="fitStart"
android:background="#00ffffff"
android:cropToPadding="false"
android:foregroundGravity="bottom"
android:layout_weight="2" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/can_pot"
android:id="@+id/button6"
android:textStyle="bold"
android:textIsSelectable="false"
android:lines="3"
android:linksClickable="false"
android:textColor="#000000"
android:background="#00ffffff"
android:layout_weight="3" />
</LinearLayout>
不知道怎么办!
从滚动视图中删除这一行
xmlns:android="http://schemas.android.com/apk/res/android"
问题可能与布局的对齐和引力有关;在 ScrollView 内的 LinearLayout 子项中,将 android:gravity="center
更改为:android:gravity="top|center"
。希望对你有帮助。
(虽然它不会给你一个错误,你可以删除第二个 xmlns:android="http://schemas.android.com/apk/res/android")
试试这个代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back1"
android:alpha=".9"> <ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha=".9"
android:gravity="center">
</LinearLayout>
</ScrollView>
我遇到了类似的问题。我的 ScrollView 中的 LinearLayout 没有按预期工作。 lineaLayout 的第一个组件不可见。 原因是android:layout_gravity="center_vertical"。将其更改为 android:layout_gravity="top|center_vertical".