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