我有一个非常奇怪的问题,按钮,垂直对中和能见度消失。在我的应用程序中,我有一个图书列表,我正在使用旋转视图库在每一行后面创建按钮。我有三个按钮:返回,发送提醒和删除。如果未借出书,则返回和发送提醒按钮可见性被动态设置为Visibility.GONE。现在我的问题是。对于行的后面,我有以下xml布局。
<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:
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的方法,所以它看起来不像。
发布于 2014-04-10 21:21:05
嗯,我想是LayoutParams吧。如果有人感兴趣,我就是这样解决的:
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);
}https://stackoverflow.com/questions/22861918
复制相似问题