android - 使用线性布局在真实设备上未显示图像

标签 android android-layout

我的布局分为 3 个,即 ImageView 和另外 2 个线性布局。每个线性布局的 imageview 权重分别为 2 和 1,总和为 4。在 android studio 中,布局运行良好,但当我尝试在真实设备上进行测试时,得到的结果如下:

enter image description here

这是 xml:

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="20dp"
    android:weightSum="4"
    tools:context="com.newvillemovement.smartmyjob.RegisterActivity_page1">

    <ImageView
        android:layout_width="match_parent"
        android:layout_weight="2"
        android:layout_gravity="top"
        android:layout_height="match_parent"
        android:id="@+id/imageView"
        android:src="@drawable/img"
        android:scaleType="fitCenter"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/imageView"
        android:layout_weight="1"
        android:layout_centerHorizontal="true"
        android:weightSum="2"
        android:id="@+id/linearLayout">

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Korean"
            android:id="@id/btnKorean"
            android:layout_marginRight="5dp"
            android:layout_weight="1"
            android:scaleType="fitCenter"
            android:onClick="btnKorean"
            android:src="@drawable/btnkoreanomal" />

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="Foreigner"
            android:id="@id/btnForeigner"
            android:layout_weight="1"
            android:scaleType="fitCenter"
            android:onClick="btnForeigner"
            android:src="@drawable/btnforeignernormal" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_weight="1"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/linearLayout"
        android:layout_marginTop="10dp"
        android:orientation="vertical">

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:text="Events"
            android:layout_weight="1"
            android:id="@+id/button3"
            android:src="@drawable/img_event_title"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:scaleType="fitCenter"
            android:layout_alignParentTop="true" />

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:id="@+id/imageView"
            android:src="@drawable/txt_event"
            android:layout_centerHorizontal="true"
            android:layout_below="@+id/button3"
            android:scaleType="fitCenter"
            android:layout_marginRight="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="10dp" />

        <ImageView
            android:id="@+id/footertext"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:text="About About About About About About About About About About About About About"
            android:src="@drawable/footer"
            android:scaleType="fitCenter"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp" />

    </LinearLayout>

</LinearLayout>

最佳答案

ImageView 和 LinearLayouts 的layout_height 必须0dp!为了让它随着重量的变化而固定,现在就试试吧。

关于android - 使用线性布局在真实设备上未显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20759576/

相关文章:

android - com.firebase.client.FirebaseException : Failed to parse node with class class CLASS_NAME android

android - 入队 onResponse 方法在 android 改造中返回空的 response.body()

安卓应用程序失败

java - 如何启动 <provider/> 标签(启动 Shazam 搜索 Activity )

java - 在 AsyncTask 中将新的 TextView 设置为 fragment

java - addToBackStack(null) 中的 null 的目的是什么?

android - Android Studio 3.0 Canary 3 的数据绑定(bind)

android - android SDK是否提供任何默认方法来像iOS一样添加模糊

android - ViewPager fragment 在抽屉导航 fragment 内第二次无法正常工作

android - 删除堆叠的 TextView 之间的空间