LinearLayout子控件始终靠底问题

当在LinearLayout中放置两个TextView,后一个始终与前一个底部对齐,即使设置了layout_marginBottom也无效。问题可能与LinearLayout的父控件——一个来自github的开源库com.tjerkw.slideexpandable.library有关。解决方案是在第一个TextView上添加layout_gravity属性,这将防止后一个TextView持续底部对齐。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先贴一段代码

 <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >


                <TextView
                    android:id="@+id/online_ktv_songlist_songname_vs"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:singleLine="true"
                    android:textColor="@color/white"
                    android:textSize="18sp" />


                <TextView
                    android:id="@+id/online_ktv_songlist_scoresign_vs"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="4dp"
                    android:layout_marginTop="3dp"
                    android:background="@drawable/score_sign_bg"
                    android:gravity="center"
                    android:paddingBottom="1dip"
                    android:paddingLeft="2dip"
                    android:paddingRight="2dip"
                    android:paddingTop="1dip"
                    android:text="@string/score_song"
                    android:textColor="@color/white"
                    android:textSize="9sp"
                    android:visibility="gone" />
            </LinearLayout>


其实就是两个TextView 放在一个linearLayout里,前一个TextView字体较大,后面较小。后面一个始终与前一个底部对齐,设置margin_bottom无效。

LinearLayout父控件是github上的一个开源控件com.tjerkw.slideexpandable.library,可能与这个有关。

后来发现在第一个TextView上设置一个Layout_gravity属性,后一个TextView就不会持续底部对齐了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值