当前位置: 代码迷 >> Android >> RelativeLayout布局的一些尴尬,该如何处理
  详细解决方案

RelativeLayout布局的一些尴尬,该如何处理

热度:75   发布时间:2016-05-01 22:09:10.0
RelativeLayout布局的一些尴尬
Java code
<?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="wrap_content"    android:background="@drawable/ic_click"    android:minHeight="66dip" >    <TextView        android:id="@+id/newstitle"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="11.3dip"        android:paddingRight="52dip"        android:paddingTop="14dip"        android:textColor="@color/black"        android:textSize="@dimen/middleTextSize"        android:textStyle="bold" >    </TextView>    <TextView        android:id="@+id/newsaddTime"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignLeft="@+id/newstitle"        android:layout_below="@+id/newstitle"        android:paddingLeft="11.3dip"        android:paddingTop="8.6dip"        android:textColor="@color/black"        android:textSize="@dimen/smallTextSize" >    </TextView>    <ImageView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentRight="true"        android:layout_centerVertical="true"        android:layout_marginRight="5.3dip"        android:src="@drawable/ic_arrow" >    </ImageView></RelativeLayout>

这个布局是@+id/newsaddTime本来应该在@+id/newstitle下面的,但实际显示的时候@+id/newsaddTime没有在@+id/newstitle的下面,而是默认在Relativelayout布局的顶端,感觉好奇怪,求大家帮忙看看

------解决方案--------------------
楼主有木有经过测试啊,怎么我把你的布局放进我的程序里一测,发现@+id/newsaddTime确实在@+id/newstitle下面??
------解决方案--------------------
有可能是你的大布局影响到了你的这个,你把你贴的代码直接拷进另外一个单独的xml里测试一下看看,如果发现结果正确,表示你的大布局有问题啊.
我自己测试了一下,确定没有你说的问题.
------解决方案--------------------
楼主把 newsaddTime 的
android:layout_alignLeft="@+id/newstitle"
android:layout_below="@+id/newstitle"
两个 +号 去掉试试


android:layout_alignLeft="@id/newstitle"
android:layout_below="@id/newstitle"

------解决方案--------------------
探讨

有可能是你的大布局影响到了你的这个,你把你贴的代码直接拷进另外一个单独的xml里测试一下看看,如果发现结果正确,表示你的大布局有问题啊.
我自己测试了一下,确定没有你说的问题.

------解决方案--------------------
Java code
<TextView        android:id="@+id/newsaddTime"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignLeft="@+id/newstitle"        android:layout_below="@+id/newstitle"  //把加号去掉看看        android:paddingLeft="11.3dip"        android:paddingTop="8.6dip"        android:textColor="@color/black"        android:textSize="@dimen/smallTextSize" >    </TextView>
------解决方案--------------------
android:layout_alignLeft="@+id/newstitle"楼主去掉这条语句看看呢
------解决方案--------------------
android:layout_alignLeft="@+id/newstitle"
这句要去掉,这应该是默认在newstitle左边了
  相关解决方案