Remove rule from button | Textview in relativelayout programmatically

Disable all already applied rule from activity view widgets dynamically using coding.

Disabling rule using coding method is very easy and after removing rule from widgets they will be set into normal before rule applying condition. So here is the complete step by step tutorial for Remove rule from button | Textview in relativelayout programmatically.

android-project-download-code-button

How to Remove rule from button | Textview in relativelayout programmatically.

Code for MainActivity.java file.

 package com.removerulebutton_android_examples.com;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

public class MainActivity extends Activity {

 Button Rrule;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 Rrule = (Button)findViewById(R.id.button1);
 final LayoutParams layoutparams = (LayoutParams) Rrule.getLayoutParams();
 
 Rrule.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 
 layoutparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
 layoutparams.addRule(RelativeLayout., 0);ALIGN_PARENT_BOTTOM
 Rrule.setLayoutParams(layoutparams);
 
 }
 });
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.removerulebutton_android_examples.com.MainActivity" >

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentBottom="true"
 android:layout_marginBottom="56dp"
 android:gravity="center_vertical"
 android:text="Remove rule from button" />

</RelativeLayout>

Screenshots:

Remove rule from button | Textview in relativelayout programmatically

remove rule successfully

Click here to download Remove rule from button | Textview in relativelayout programmatically project.

Leave a Reply

Your email address will not be published. Required fields are marked *