我有一个有孩子的相对布局(3个按钮和edittext)。最初,布局位于父布局的底部,这是一种线性布局。点击其中一个按钮,我将它放在屏幕顶部(父线性布局),我能够实现这一点。但是点击另一个按钮我希望它再次处于原始位置,即在屏幕的底部。请帮忙。这是xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/msg_detail_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/TitleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:src="@drawable/backbutton" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:singleLine="true"
android:textSize="30sp" />
</LinearLayout>
<RelativeLayout
android:id="@+id/post_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:visibility="gone" >
<ImageView
android:id="@+id/post_upd_frame1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/post_upd_frame" />
<EditText
android:id="@+id/update_edit_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/post_upd_frame1"
android:layout_alignRight="@id/post_upd_frame1"
android:background="@android:color/transparent"
android:inputType="textMultiLine"
android:maxLines="5"
android:singleLine="false"
android:focusable="true"
android:padding="10dp"
android:visibility="gone">
</EditText>
<ImageButton
android:id="@+id/post_btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/post_upd_frame1"
android:layout_alignRight="@id/post_upd_frame1"
android:layout_margin="5dp"
android:layout_marginLeft="5dp"
android:background="@android:color/transparent"
android:src="@drawable/post_message" />
<ImageButton
android:id="@+id/post_picture_btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/post_upd_frame1"
android:layout_margin="5dp"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="@id/post_btn1"
android:background="@android:color/transparent"
android:src="@drawable/add_picture" />
<ImageButton
android:id="@+id/post_Cancel_btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/post_upd_frame1"
android:layout_alignParentLeft="true"
android:layout_margin="5dp"
android:layout_toLeftOf="@id/post_picture_btn1"
android:background="@android:color/transparent"
android:src="@drawable/cancel_message" />
<ImageView
android:id="@+id/post_update_spinner_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/post_btn1"
android:layout_centerHorizontal="true"
android:src="@drawable/running_indicator"
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/reply_action_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_above="@id/post_layout1"
android:orientation="horizontal">
<ImageButton
android:id="@+id/delete_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:background="@android:color/transparent"
android:paddingBottom="5dp"
android:src="@drawable/xml_delete_button_selector" />
<ImageButton
android:id="@+id/reply_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@id/delete_button"
android:background="@android:color/transparent"
android:paddingBottom="5dp"
android:src="@drawable/xml_reply_button_selector" />
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/sent_received"
android:layout_alignTop="@+id/reply_button"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:layout_margin="10dp"
android:textColor="@android:color/white"
android:textSize="14sp" />
<ImageView
android:id="@+id/sent_received"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/reply_button"
android:background="@android:color/transparent"
android:src="@drawable/received" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
点击reply_button我将相对布局“post_layout”定位在屏幕顶部,我可以这样做,但是点击post_cancel_button我希望相对布局“post_layout”再次位于屏幕底部。这是我用来将布局推到屏幕顶部的代码:
RelativeLayout.LayoutParams rparams = (RelativeLayout.LayoutParams) mPostLayout.getLayoutParams();
rparams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
mPostLayout.setLayoutParams(rparams);
按钮代码:
mReplyButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
RelativeLayout.LayoutParams rparams = (RelativeLayout.LayoutParams) mPostLayout.getLayoutParams();
rparams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
mPostLayout.setLayoutParams(rparams);
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mUpdateEditView, InputMethodManager.SHOW_FORCED);
}
});
mMessageReplyCancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
RelativeLayout.LayoutParams rparams = (RelativeLayout.LayoutParams) mPostLayout.getLayoutParams();
rparams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
mPostLayout.setLayoutParams(rparams);
}
});
mPostLayout是我想要定位的相对布局的名称,来自xml的post_layout
答案 0 :(得分:0)
当你第一次点击时获得原始位置并第二次点击然后重置原始位置