在android 控件对齐中怎样设置一个控件居于另一控件中央,让他们对齐。

二次元同好交流新大陆
扫码下载App
汇聚2000万达人的兴趣社区下载即送20张免费照片冲印
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
真正懂的人,从来不问为什么!
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(9934)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_085075',
blogTitle:'解决LinearLayout中控件不能居右对齐',
blogAbstract:'
在LinearLayout布局时使用右对齐(android:layout_gravity=\"right\")控件对齐方式不生效,需要设置 android:layout_weight=\"1\" 才能右对齐控件,原因在于后者把位置平分了。
blogTag:'android,linearlayout,对齐',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:4,
publishTime:2,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'真正懂的人,从来不问为什么!',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}android&相对布局RelativeLayout中的一些属性的使用和实例
第一组layout相对布局属性
& android:layout_below
& android:layout_above
& android:layout_toLeftOf
android:layout_toRightOf(
注:此属性时写在控件标签内部,用于控制控件的浮动,类似于CSS中的float属性.
android:id="@+id/firstView"
android:text="第一个TextView"
android:id="@+id/secondView"
android:text="第二个TextView"
android:layout_toRightOf="@id/firstView"
给第二个TextView控件添加toRightOf属性,并把第一个TextView控件的id赋值给它,作用
让第二个TextView处于第一个TextView控件的右方.
其他属性以此类推
___________________________________________________________________________________________________________________
第二组Layout相对布局属性
& android:layout_alignLeft
android:layout_alignRight
android:layout_alignTop
android:layout_alignBottom
注:此组属性时控制控件的对齐方式,分别对应为
左对齐 右对齐 上对齐和下对齐
android:id="@+id/firstView"
android:text="第一个TextView"
android:id="@+id/secondView"
android:text="TextView"
android:layout_alignRight="@id/firstView"
alignRight属性应用前:
alignRight属性应用后
其他属性以此类推
___________________________________________________________________________________________________________________
第三组layout相对布局属性
& android:layout_alignBaseLine
注:此属性是让控件中的text(仅限于拉丁语系字母)以基准线为标准对齐.
android:id="@+id/firstView"
android:text="Hello"
android:id="@+id/secondView"
android:text="World"
android:layout_toRightOf="@id/firstView"
android:layout_alignBaseLine="@id/FirstView"
layout_alignBaseLine属性应用前:
layout_alignBaseLine属性应用后:
___________________________________________________________________________________________________________________
第四组layout相对布局属性:
& android_layout_alignParentLeft
android_layout_alignParentRight
android_layout_alignParentTop
android_layout_alignParentBottom
注:此组属性是让该属性拥有者与父控件边缘对齐
RelativeLayout
& android:background="#00FF00"
& android:layout_width="match_parent"
android:layout_height="match_parent"
& TextView&
android:text="TextView"
android:background="#FF0000"
android:layout_alignParentRight="True"
RelativeLayout
(注:TextView的父控件是RelativeLayout,其他以此类推)
layout_alignParentRight属性应用前:
layout_alignParentRight属性应用后:
其他属性以此类推
___________________________________________________________________________________________________________________
第四组layout相对布局属性:
& android:layout_centerInParent(位于父控件的正中央)
android:layout_centerHorizontal(位于父控件的垂直方向正中央)
android:layout_centerVertical(位于父控件的水平方向正中央)
注:此类属性用于对齐至父控件的中央
RelativeLayout
android:background="#00FF00"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView"
android:background="#FF0000"
android:layout_alignParentRight="True"
RelativeLayout
应用layout_centerInParent后:
应用layout_centerHorizontal后:
应用layout_centerVertical后:
___________________________________________________________________________________________________________________
第五组layout相对布局属性:
android:layout_alignStart
android:layout_alignEnd
android:layout_alignParentStart
android:layout_alignParentEnd
注:此组属性与上面的4组属性有许多重合的地方,可根据不同的需要灵活的掌握.
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。下次自动登录
现在的位置:
& 综合 & 正文
android 让一个控件按钮居于底部的几种方法
android 让一个控件按钮居于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" &!-- 这里不能设置fill_parent --&android:layout_weight="1" &!-- 这里设置layout_weight=1是最关键的,否则底部的LinearLayout无法到底部 --&2. 采用relativelayout布局:android:layout_alignParentBottom="true" &!-- 这里设置layout_alignParentBottom=true是最关键的,这个属性上级必须是RelativeLayout --&
3. 采用 fragment 布局(activitygroup 已经被弃用不建议使用)
=====================================1.采用linearlayout布局:
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"&
&LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="0dp" &!-- 这里不能设置fill_parent --&
android:layout_weight="1" &!-- 这里设置layout_weight=1是最关键的,否则底部的LinearLayout无法到底部 --&
android:orientation="vertical"&
&/LinearLayout&
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical"&
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/runbackground"
android:focusable="false" /&
&/LinearLayout&
&/LinearLayout&
2. 采用relativelayout布局:
&RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"&
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"&
&/LinearLayout&
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" &!-- 这里设置layout_alignParentBottom=true是最关键的,这个属性上级必须是RelativeLayout --&
android:orientation="vertical"&
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/runbackground"
android:focusable="false" /&
&/LinearLayout&
&/RelativeLayout&
3. 采用 fragment 布局(activitygroup 已经被弃用不建议使用)&?xml version="1.0" encoding="utf-8"?&&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" &
&fragment class="com.xuzhi.fragment.FragmentDemoActivity$TitlesFragment" android:id="@+id/titles" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent"
&FrameLayout android:id="@+id/details" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent"
android:background="?android:attr/detailsElementBackground"
&&/FrameLayout&
&/LinearLayout&
==============================================
&&&&推荐文章:
【上篇】【下篇】android 让一个控件按钮居于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" &!-- 这里不能设置fill_parent --&android:layout_weight="1" &!-- 这里设置layout_weight=1是最关键的,否则底部的LinearLayout无法到底部 --&2. 采用relativelayout布局:android:layout_alignParentBottom="true" &!-- 这里设置layout_alignParentBottom=true是最关键的,这个属性上级必须是RelativeLayout --&
3. 采用 fragment 布局(activitygroup 已经被弃用不建议使用)
=====================================1.采用linearlayout布局:
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"&
&LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="0dp" &!-- 这里不能设置fill_parent --&
android:layout_weight="1" &!-- 这里设置layout_weight=1是最关键的,否则底部的LinearLayout无法到底部 --&
android:orientation="vertical"&
&/LinearLayout&
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical"&
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/runbackground"
android:focusable="false" /&
&/LinearLayout&
&/LinearLayout&
2. 采用relativelayout布局:
&RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"&
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"&
&/LinearLayout&
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" &!-- 这里设置layout_alignParentBottom=true是最关键的,这个属性上级必须是RelativeLayout --&
android:orientation="vertical"&
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/runbackground"
android:focusable="false" /&
&/LinearLayout&
&/RelativeLayout&
3. 采用 fragment 布局(activitygroup 已经被弃用不建议使用)&?xml version="1.0" encoding="utf-8"?&&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" &
&fragment class="com.xuzhi.fragment.FragmentDemoActivity$TitlesFragment" android:id="@+id/titles" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent"
&FrameLayout android:id="@+id/details" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent"
android:background="?android:attr/detailsElementBackground"
&&/FrameLayout&
&/LinearLayout&
==============================================
阅读(...) 评论()}

我要回帖

更多关于 android 控件中心对齐 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信