首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有按钮和能见度消失的奇怪行为

有按钮和能见度消失的奇怪行为
EN

Stack Overflow用户
提问于 2014-04-04 11:44:33
回答 1查看 263关注 0票数 0

我有一个非常奇怪的问题,按钮,垂直对中和能见度消失。在我的应用程序中,我有一个图书列表,我正在使用旋转视图库在每一行后面创建按钮。我有三个按钮:返回,发送提醒和删除。如果未借出书,则返回和发送提醒按钮可见性被动态设置为Visibility.GONE。现在我的问题是。对于行的后面,我有以下xml布局。

代码语言:javascript
复制
<LinearLayout
        android:id="@+id/swipelist_backview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:tag="swipelist_backview"
        android:background="#101010">
                <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="55px"
                android:layout_gravity="center_vertical"
                android:id="@+id/swipe_button1"
                android:text="@string/markAsReturned"/>

                <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:id="@+id/swipe_button2"
                android:layout_gravity="center_vertical"
                android:text="@string/sendReminder"/>

                <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:id="@+id/swipe_button3"
                android:layout_gravity="center_vertical"
                android:text="@string/delete"/>


</LinearLayout>

现在,预期的结果是,按钮将垂直居中的每一行,这确实发生,如果这本书是借来的,所有的按钮是可见的。但是,如果没有借出这本书,唯一显示的按钮是“删除”,并没有对齐。

我还使用以下代码将删除按钮的左边边距设置为55 px:

代码语言:javascript
复制
if(!item.isLended())
{
    btnReturn.setVisibility(View.GONE);
    btnSendReminder.setVisibility(View.GONE);
    LayoutParams lp = new LayoutParams(btnDelete.getLayoutParams());
    lp.setMargins(55, 0, 0, 0);
    btnDelete.setLayoutParams(lp);
}

我认为这可能是删除了真正的对齐,但是LayoutParams似乎没有设置layout-gravity的方法,所以它看起来不像。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-10 21:21:05

嗯,我想是LayoutParams吧。如果有人感兴趣,我就是这样解决的:

代码语言:javascript
复制
if(!item.isLended())
{
    btnReturn.setVisibility(View.GONE);
    btnSendReminder.setVisibility(View.GONE);
    LayoutParams lp = new LayoutParams(btnDelete.getLayoutParams());
    lp.setMargins(55, 0, 0, 0);
    lp.gravity = Gravity.CENTER_VERTICAL;
    btnDelete.setLayoutParams(lp);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22861918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档