请教一下android的布局问题!!!

月盡天明
博客专家认证
2014-11-07 03:44:16
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:orientation="vertical" >

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/corner1" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/corner2" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="@drawable/corner3" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/corner4" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dian" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/d_units_info1"
android:textColor="@color/d_units_info"
android:textSize="@dimen/d_units_info" />
</LinearLayout>
</RelativeLayout>

</LinearLayout>


中间的相对布局我设置的是wrap_content,但是为什么它直接铺满屏幕了???
显示效果如下:
...全文
386 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
月盡天明 2014-11-10
  • 打赏
  • 举报
回复
引用 7 楼 Tyler3419 的回复:
[quote=引用 4 楼 crazy1235 的回复:] [quote=引用 3 楼 Tyler3419 的回复:] 建议改变思路,用背景图片实现。做一张四个角可拉伸的.9图片,直接设置下面这个布局的background就得完美达到你要的效果。
<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
 
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/dian" />
 
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/d_units_info1"
                android:textColor="@color/d_units_info"
                android:textSize="@dimen/d_units_info" />
        </LinearLayout>
你的这种方法可行!!! 但是我的方法错误在哪? 请指教!!!!![/quote] 主要是因为
android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
这个属性,而且它的上一层又是
 android:layout_width="wrap_content"
        android:layout_height="wrap_content"
所有达不到你要的效果。 [/quote] 你觉得我应该怎么写?请指教!!!
lazyzoon 2014-11-10
  • 打赏
  • 举报
回复
引用 4 楼 crazy1235 的回复:
[quote=引用 3 楼 Tyler3419 的回复:] 建议改变思路,用背景图片实现。做一张四个角可拉伸的.9图片,直接设置下面这个布局的background就得完美达到你要的效果。
<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
 
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/dian" />
 
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/d_units_info1"
                android:textColor="@color/d_units_info"
                android:textSize="@dimen/d_units_info" />
        </LinearLayout>
你的这种方法可行!!! 但是我的方法错误在哪? 请指教!!!!![/quote] 主要是因为
android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
这个属性,而且它的上一层又是
 android:layout_width="wrap_content"
        android:layout_height="wrap_content"
所有达不到你要的效果。
lazyzoon 2014-11-10
  • 打赏
  • 举报
回复
引用 8 楼 crazy1235 的回复:
[quote=引用 7 楼 Tyler3419 的回复:] [quote=引用 4 楼 crazy1235 的回复:] [quote=引用 3 楼 Tyler3419 的回复:] 建议改变思路,用背景图片实现。做一张四个角可拉伸的.9图片,直接设置下面这个布局的background就得完美达到你要的效果。
<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
 
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/dian" />
 
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/d_units_info1"
                android:textColor="@color/d_units_info"
                android:textSize="@dimen/d_units_info" />
        </LinearLayout>
你的这种方法可行!!! 但是我的方法错误在哪? 请指教!!!!![/quote] 主要是因为
android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
这个属性,而且它的上一层又是
 android:layout_width="wrap_content"
        android:layout_height="wrap_content"
所有达不到你要的效果。 [/quote] 你觉得我应该怎么写?请指教!!![/quote] 你把最上层布局的
android:layout_width="match_parent"
                  android:layout_height="match_parent"
改成wrap_content属性,你要全黑的效果可以在activity的style定义 你试试看行不行,能不能达到你的效果。
shixufeng421 2014-11-09
  • 打赏
  • 举报
回复
楼上的回复都不错啊,应该可以解决问题,楼主看看就行吧
zhangwhhx 2014-11-09
  • 打赏
  • 举报
回复
继续深入研究一下。
月盡天明 2014-11-08
  • 打赏
  • 举报
回复
引用 3 楼 Tyler3419 的回复:
建议改变思路,用背景图片实现。做一张四个角可拉伸的.9图片,直接设置下面这个布局的background就得完美达到你要的效果。
<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
 
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/dian" />
 
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/d_units_info1"
                android:textColor="@color/d_units_info"
                android:textSize="@dimen/d_units_info" />
        </LinearLayout>
你的这种方法可行!!! 但是我的方法错误在哪? 请指教!!!!!
lazyzoon 2014-11-08
  • 打赏
  • 举报
回复
建议改变思路,用背景图片实现。做一张四个角可拉伸的.9图片,直接设置下面这个布局的background就得完美达到你要的效果。
<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
 
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/dian" />
 
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/d_units_info1"
                android:textColor="@color/d_units_info"
                android:textSize="@dimen/d_units_info" />
        </LinearLayout>
月盡天明 2014-11-08
  • 打赏
  • 举报
回复
引用 1 楼 s715575807 的回复:
不要同时设置android:layout_alignParentLeft与android:layout_alignParentRight,还有android:layout_alignParentTop与android:layout_alignParentBottom
不这样设置我,怎么把四个边角的图片放到 四个角落里呢?
s_wenze 2014-11-07
  • 打赏
  • 举报
回复
不要同时设置android:layout_alignParentLeft与android:layout_alignParentRight,还有android:layout_alignParentTop与android:layout_alignParentBottom

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧