Android 在屏幕顶部显示图像
我想显示屏幕顶部和屏幕底部的一些按钮的图像。我写了这段代码,但图片没有显示!我怎样才能解决这个问题?若我将图像转换为非相对性页面,图像显示页面顶部,但视图显示为我将顶部页面的底部页面分开。为什么? 按钮的另一个问题。btn4按钮显示其他按钮上方的一点?为什么?Android 在屏幕顶部显示图像,android,button,view,Android,Button,View,我想显示屏幕顶部和屏幕底部的一些按钮的图像。我写了这段代码,但图片没有显示!我怎样才能解决这个问题?若我将图像转换为非相对性页面,图像显示页面顶部,但视图显示为我将顶部页面的底部页面分开。为什么? 按钮的另一个问题。btn4按钮显示其他按钮上方的一点?为什么? <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/background">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0"
android:layout_gravity="bottom">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/smallyelowbar"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_alignParentTop="true"/>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/background" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<Button android:id="@+id/btn1"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/more_selector"/>
<Button
android:id="@+id/btn2"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/contact_selector"/>
<Button android:id="@+id/btn3"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/product_selector"/>
<Button android:id="@+id/btn4"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/introduce_selector"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
在我看来,您的框架布局将ImageView隐藏在其背后。 尝试将FrameLayout放在ImageView下方(通过在其上设置android:below=属性,或者通过将ImageView放在xml中的FrameLayout上方)。您可以尝试此方法
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/bottom" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:background="#495663"
android:scaleType="fitXY" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="@+id/btn1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#DBEAF9" />
<Button
android:id="@+id/btn2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#DBEAF9" />
<Button
android:id="@+id/btn3"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#DBEAF9" />
<Button
android:id="@+id/btn4"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#DBEAF9" />
</RelativeLayout>
</RelativeLayout>
工作完美。快乐编码试试这个XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/relative_btngroup"
android:background="@drawable/ic_launcher" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relative_btngroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btn1" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btn2" />
<Button
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btn3" />
</RelativeLayout>
</RelativeLayout>
这里的问题是框架布局与图像视图重叠。。。这就是为什么当你把它移出相对布局时它会工作的原因 请尝试下面的代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/background">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0"
android:layout_gravity="bottom">
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/background" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/smallyelowbar"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_alignParentTop="true"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<Button android:id="@+id/btn1"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/more_selector"/>
<Button
android:id="@+id/btn2"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/contact_selector"/>
<Button android:id="@+id/btn3"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/product_selector"/>
<Button android:id="@+id/btn4"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/introduce_selector"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
为什么你要将你的布局包装在linearlayout中?你不能与RelativeLayout一起工作吗?谢谢你的快速回复,但我不明白你在说什么。请多加补偿。