RelativeLayout的alignWithParentIfMissing

2023-10-27 17:48

本文主要是介绍RelativeLayout的alignWithParentIfMissing,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

针对RelativeLayout有一点需要注意,因为它内部是通过多个View之间的关系而确定的框架,那么当其中某一个View因为某些需要调用GONE 来完全隐藏掉后,会影响与其相关联的Views。Android为我们提供了一个属性 alignWithParentIfMissing  用于解决类似问题,当某一个View无法找到与其相关联 的Views后将依据alignWithParentIfMissing 的设定判断是否与父级View对齐。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="fill_parent"  android:layout_height="?android:attr/listPreferredItemHeight"  android:padding="6dip">  <ImageView  android:id="@+id/icon"  android:layout_width="wrap_content"  android:layout_height="fill_parent"  android:layout_alignParentTop="true"  android:layout_alignParentBottom="true"  android:layout_marginRight="6dip"  android:src="@drawable/icon" />  <TextView    android:id="@+id/secondLine"  android:layout_width="fill_parent"  android:layout_height="26dip"   android:layout_toRightOf="@id/icon"  android:layout_alignParentBottom="true"  android:layout_alignParentRight="true"  android:singleLine="true"  android:ellipsize="marquee"  android:text="Simple application that shows how to use RelativeLayout" />  <TextView  android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:layout_toRightOf="@id/icon"  android:layout_alignParentRight="true"  android:layout_alignParentTop="true"  android:layout_above="@id/secondLine"  android:layout_alignWithParentIfMissing="true"  android:gravity="center_vertical"  android:text="My Application" />  
</RelativeLayout> 


这篇关于RelativeLayout的alignWithParentIfMissing的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/287322

相关文章

RelativeLayout 深入理解

今天做app底部的导航栏,就是会有一个分割线,分割内容和下面的fragmenttablehost,那条线,我看开源中国是用relativelayout包裹的。 我也包裹,但是不行。显示不出来那条线。 后来我意识到是顺序的问题,也就是fragmenttablehost在下面,就会把上面的view那一层覆盖掉,导致出现不了分隔栏。 总之: <RelativeLayoutandroid:lay

RelativeLayout相对布局

activity_relative_layout.xml <?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_h

flutter 类似Android 中RelativeLayout在末尾居中

1,Android RelativeLayout中写法: <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:id="@+id/

RelativeLayout布局参数汇总

控件相对于布局的位置参数: android:layout_alignParentLeft=”true”//表示控件的左边缘与父布局的左边缘对齐 android:layout_alignParentTop=”true” android:layout_alignParentRight=”true” android:layout_alignParentBottom=”true” 控件相对于

RelativeLayout 自定义TabHost效果

原文地址 http://www.pocketdigi.com/20110812/442.html TabHost如果要自定义显示的效果,有点麻烦,而默认的样式有时候又与我们程序的风格不匹配.今天我们就用RelativeLayout来实现与TabHost相同的功能.上效果图: 点击上面的tab,tab自身样式会改变,下面内容也会改变,功能完全与TabHost相同. 介绍一下Relat

【Android】三种常见的布局LinearLayout、GridLayout、RelativeLayout

【Android】三种常见的布局LinearLayout、GridLayout、RelativeLayout 在 Android 开发中,布局(Layout)是构建用户界面的基础。通过合理的布局管理,可以确保应用在不同设备和屏幕尺寸上都能有良好的用户体验。本文将简单介绍 Android 中的三种常见布局管理器:线性布局(LinearLayout)、网格布局(GridLayout)和相对布局(Re

android开发RelativeLayout用到的一些重要的属性

RelativeLayout用到的一些重要的属性:   第一类:属性值为true或false  android:layout_centerHrizontal 水平居中  android:layout_centerVertical 垂直居中  android:layout_centerInparent 相对于父元素完全居中  android:layout_alignParentBottom

Android RelativeLayout Rtl布局下的bug:paddingStart会同时作用于左右内边距

问题现象 如上图,只是设置了paddingStart,在RTL布局下,左右都产生了10dp的间距。其他布局如LinearLayout,FrameLayout则没有这个问题。 private void positionAtEdge(View child, LayoutParams params, int myWidth) {if (isLayoutRtl()) {// myWidth是

Android布局控件之RelativeLayout详解

Android布局控件之RelativeLayout详解 RelativeLayout是相对布局,相对布局指的是某个组件的位置是相对于它所以来的组件的位置   android布局属性详解 RelativeLayout用到的一些重要的属性:       第一类:属性值为true或false    android:layout_centerHrizontal  水平居中    android

32、自定义组件RelativeLayout、设置组合控件的状态

自定义控件步骤: 测量:onMeasure  设置自己显示在屏幕上的宽高 布局:onLayout   设置自己显示在屏幕上的位置(只有在自定义ViewGroup中才用到) 绘制:onDraw     控制显示在屏幕上的样子(自定义viewgroup时不需要这个) View和ViewGroup的区别 1.他们都需要进行测量操作 2.ViewGroup主要是控制子view如何摆放,所以必须实