[英]Android: Linear layout inside scrollview is not showing
在scrollview中也有一些線性布局。 當我在HUAWEI Mate7上安裝應用程序時,它可以正常工作。 但是在Samsung 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>
我不知道該怎么辦!
問題可能與布局的對齊方式和重力有關。 在ScrollView內的LinearLayout子級中,將android:gravity="center
更改為: android:gravity="top|center"
希望對您有所幫助。
(並且盡管它沒有給您錯誤,但是您可以刪除第二個xmlns:android =“ http://schemas.android.com/apk/res/android”)
我有一個類似的問題。 ScrollView內部的LinearLayout未能按預期工作。 lineaLayout的第一個組件不可見。 原因是android:layout_gravity =“ center_vertical”。 將其更改為android:layout_gravity =“ top | center_vertical”。
從滾動視圖中刪除此行
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.