2017-06-21 106 views
1

我的付款方式有兩種選擇,即Credit CardE-Check。當我選擇了Credit Card,佈局應該表現出這樣的事情 The layout when the credit card is selected如何在選擇單選按鈕後在Android中管理佈局?

問題是,當我選擇E-Check佈局顯示了這樣的事情, The layout after I select the e-c

我要的是刪除之間的差距單選按鈕以及點擊E-Check option後的內容,並在信用卡顯示其內容的相同位置顯示電子支票內容。如果在沒有選擇任何東西時知道如何顯示什麼,它會更有幫助。

Layout.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:fillViewport="true"> 

<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="1000dp" 
    android:background="@color/whitecolor" 

    tools:context=".Payment"> 


    <ImageView 
     android:id="@+id/layout" 
     android:layout_width="150dp" 
     android:layout_height="120dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="5dp" 
     android:background="#FFF" 
     android:src="@drawable/logo" /> 


    <LinearLayout 
     android:id="@+id/linearLayout3" 
     android:layout_width="300dp" 
     android:layout_height="60dp" 
     android:layout_alignEnd="@+id/linearLayout2" 
     android:layout_alignStart="@+id/linearLayout2" 
     android:layout_below="@+id/linearLayout2"> 

     <TextView 
      android:id="@+id/paymentduedate" 
      android:layout_width="117dp" 
      android:layout_height="18dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="30dp" 
      android:text="Payment Date" 
      android:textColor="@color/menucolor" 
      android:textSize="15dp" 
      android:textStyle="bold" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="60dp" 
      android:layout_marginLeft="10dp"> 


      <EditText 
       android:id="@+id/txtpaymentmonth" 
       android:layout_width="100dp" 
       android:layout_height="40dp" 
       android:layout_marginLeft="5dp" 
       android:layout_marginTop="10dp" 
       android:ems="10" 
       android:hint="MM" 
       android:inputType="number" 
       android:paddingTop="10dp" 
       android:textColorHint="@color/menucolor" /> 

      <EditText 
       android:id="@+id/txtpaymentyear" 
       android:layout_width="100dp" 
       android:layout_height="40dp" 
       android:layout_marginLeft="5dp" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="10dp" 
       android:layout_weight="1" 
       android:ems="10" 
       android:hint="YYYY" 
       android:inputType="number" 
       android:textColorHint="@color/menucolor" /> 
     </LinearLayout> 


    </LinearLayout> 


    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="300dp" 
     android:layout_height="70dp" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/layout" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:layout_marginTop="22dp" 
     android:weightSum="1"> 


     <TextView 
      android:id="@+id/paymentamount" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="40dp" 
      android:text="Payment Amount" 
      android:textColor="@color/menucolor" 
      android:textSize="15dp" 
      android:textStyle="bold" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="60dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="5dp" 
      android:orientation="horizontal" 
      android:weightSum="1"> 

      <EditText 
       android:id="@+id/txtpaymentamount" 
       android:layout_width="192dp" 
       android:layout_height="40dp" 
       android:layout_marginBottom="5dp" 
       android:layout_marginEnd="5dp" 
       android:layout_marginRight="20dp" 
       android:layout_marginStart="10dp" 
       android:layout_marginTop="16dp" 
       android:layout_weight="0.39" 
       android:ems="10" 
       android:hint="00.0" 
       android:inputType="number" 
       android:paddingRight="10dp" 
       android:textColorHint="@color/menucolor" /> 
     </LinearLayout> 


    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayout4" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:layout_alignEnd="@+id/linearLayout3" 
     android:layout_alignStart="@+id/linearLayout3" 
     android:layout_below="@+id/linearLayout3" 
     android:orientation="horizontal" 
     android:weightSum="1"> 

     <TextView 
      android:id="@+id/paymentvia" 
      android:layout_width="117dp" 
      android:layout_height="18dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="25dp" 
      android:text="Payment Via" 
      android:textColor="@color/menucolor" 
      android:textSize="15dp" 
      android:textStyle="bold" /> 

     <RadioGroup 
      android:id="@+id/radioGroup1" 
      android:layout_width="225dp" 
      android:layout_height="match_parent" 
      android:layout_marginEnd="5dp" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:orientation="horizontal" 
      android:paddingBottom="15dp" 
      android:paddingLeft="5dp" 
      android:paddingStart="1dp" 
      android:weightSum="2"> 

      <RadioButton 
       android:id="@+id/rdocreditcard" 
       android:layout_width="wrap_content" 
       android:layout_height="30dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginTop="10dp" 
       android:text="Credit card" 
       android:textColor="@color/menucolor" /> 

      <RadioButton 
       android:id="@+id/rdoEcheck" 
       android:layout_width="match_parent" 
       android:layout_height="30dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginTop="10dp" 
       android:paddingEnd="5dp" 
       android:text="E-Check" 
       android:textColor="@color/menucolor" /> 
     </RadioGroup> 

    </LinearLayout> 



    <LinearLayout 
     android:id="@+id/linearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:layout_alignEnd="@+id/linearLayout4" 
     android:layout_alignStart="@+id/linearLayout4" 
     android:layout_below="@+id/linearLayout4" 
     android:orientation="horizontal" 
     android:weightSum="1"> 


     <EditText 
      android:id="@+id/txtcreaditcardnumber" 
      android:layout_width="181dp" 
      android:layout_height="40dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_weight="0.91" 
      android:ems="10" 
      android:hint="Credit Card Number" 
      android:inputType="number" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" 
      android:textColorHint="@color/menucolor" /> 


     <!-- 
     <EditText 
      android:id="@+id/expmonth" 
      android:layout_width="61dp" 
      android:layout_height="40dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:ems="10" 
      android:hint="MM" 
      android:inputType="number" 
      android:textColorHint="@color/menucolor" /> 

     <EditText 
      android:id="@+id/expyear" 
      android:layout_width="61dp" 
      android:layout_height="40dp" 
      android:layout_marginLeft="8dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_weight="0.17" 
      android:ems="10" 
      android:hint="YYYY" 
      android:inputType="number" 
      android:textColorHint="@color/menucolor" /> 

     <EditText 
      android:layout_width="61dp" 
      android:layout_height="40dp" 
      android:layout_marginRight="5dp" 
      android:layout_marginTop="10dp" 
      android:hint="CCV" 
      android:textColorHint="@color/menucolor" 
      /> 

      --> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayout5" 
     android:layout_width="200dp" 
     android:layout_height="60dp" 
     android:layout_alignEnd="@+id/linearLayout" 
     android:layout_alignStart="@+id/linearLayout" 
     android:layout_below="@+id/linearLayout"> 

     <EditText 
      android:id="@+id/txtexpirymonth" 
      android:layout_width="150dp" 
      android:layout_height="40dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_weight="0.00" 
      android:ems="10" 
      android:hint="MM" 
      android:inputType="number" 
      android:textColorHint="@color/menucolor" /> 

     <EditText 
      android:id="@+id/txtexpiryyear" 
      android:layout_width="150dp" 
      android:layout_height="40dp" 
      android:layout_marginLeft="8dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:ems="10" 
      android:hint="YYYY" 
      android:inputType="number" 
      android:textColorHint="@color/menucolor" /> 

     <EditText 
      android:id="@+id/txtexpiryyear" 
      android:layout_width="61dp" 
      android:layout_height="40dp" 
      android:layout_marginRight="5dp" 
      android:layout_marginTop="10dp" 
      android:hint="CCV" 
      android:textColorHint="@color/menucolor" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayout6" 
     android:layout_width="200dp" 
     android:layout_height="60dp" 
     android:layout_alignEnd="@+id/linearLayout5" 
     android:layout_alignStart="@+id/linearLayout5" 
     android:layout_below="@+id/linearLayout5"> 

     <EditText 
      android:id="@+id/txtfirstname" 
      android:layout_width="145dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_weight="0.11" 
      android:ems="10" 
      android:hint="First Name" 
      android:inputType="textPersonName" 
      android:textColorHint="@color/menucolor" /> 

     <EditText 
      android:id="@+id/txtlname" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="7dp" 
      android:layout_marginTop="10dp" 
      android:layout_weight="0.81" 
      android:ems="10" 
      android:hint="Last Name" 
      android:inputType="textPersonName" 
      android:textColorHint="@color/menucolor" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="200dp" 
     android:layout_height="60dp" 
     android:layout_below="@+id/linearLayout6" 
     android:layout_alignStart="@+id/linearLayout6" 
     android:layout_alignEnd="@+id/linearLayout6" 
     android:id="@+id/linearLayout7"> 

     <EditText 
      android:id="@+id/txtaddress" 
      android:layout_width="149dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:ems="10" 
      android:hint="Address" 
      android:inputType="textPersonName" 
      android:textColorHint="@color/menucolor" /> 

     <EditText 
      android:id="@+id/txtcity" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_weight="1" 
      android:ems="10" 
      android:hint="City" 
      android:inputType="textPersonName" 
      android:textColorHint="@color/menucolor" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="200dp" 
     android:layout_height="60dp" 
     android:layout_below="@+id/linearLayout7" 
     android:layout_alignStart="@+id/linearLayout7" 
     android:layout_alignEnd="@+id/linearLayout7" 
     android:weightSum="1" 
     android:id="@+id/linearLayout8"> 


     <EditText 
      android:id="@+id/txtstate" 
      android:layout_width="101dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:ems="10" 
      android:inputType="textPersonName" 
      android:hint="State" 
      android:textColorHint="@color/menucolor"/> 

     <EditText 
      android:id="@+id/txtzipcode" 
      android:layout_width="118dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:ems="10" 
      android:inputType="textPersonName" 

      android:hint="Zip code" 
      android:textColorHint="@color/menucolor"/> 

     <EditText 
      android:id="@+id/txtcountry" 
      android:layout_width="118dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:ems="10" 
      android:inputType="textPersonName" 

      android:hint="Country" 
      android:textColorHint="@color/menucolor"/> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="200dp" 
     android:layout_height="60dp" 
     android:weightSum="1" 
     android:layout_below="@+id/linearLayout8" 
     android:layout_alignStart="@+id/linearLayout8" 
     android:layout_alignEnd="@+id/linearLayout8" 
     android:id="@+id/linearLayout9"> 

     <EditText 
      android:id="@+id/txtabaroutingnumber" 
      android:layout_width="186dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:ems="10" 
      android:inputType="number" 
      android:hint="ABA Routing Number" 
      android:textColorHint="@color/menucolor" 
      android:layout_weight="0.05" /> 

     <EditText 
      android:id="@+id/txtaccountnumber" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="5dp" 
      android:layout_marginTop="10dp" 
      android:layout_weight="0.84" 
      android:ems="10" 
      android:hint="Account Number" 
      android:inputType="number" 
      android:textColorHint="@color/menucolor" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="200dp" 
     android:layout_height="60dp" 
     android:weightSum="1" 
     android:layout_below="@+id/linearLayout9" 
     android:layout_alignStart="@+id/linearLayout9" 
     android:layout_alignEnd="@+id/linearLayout9" 
     android:id="@+id/linearLayout10"> 

     <EditText 
      android:id="@+id/txtbankname" 
      android:layout_width="186dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:ems="10" 
      android:inputType="number" 
      android:hint="Bank Name" 
      android:textColorHint="@color/menucolor" 
      android:layout_weight="0.05" /> 

     <EditText 
      android:id="@+id/txtaccountname" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="5dp" 
      android:layout_marginTop="10dp" 
      android:layout_weight="0.84" 
      android:ems="10" 
      android:hint="Account Name" 
      android:inputType="number" 
      android:textColorHint="@color/menucolor" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="200dp" 
     android:layout_height="60dp" 
     android:weightSum="1" 
     android:layout_below="@+id/linearLayout10" 
     android:layout_alignStart="@+id/linearLayout10" 
     android:layout_alignEnd="@+id/linearLayout10"> 

     <EditText 
      android:id="@+id/txtaccounttype" 
      android:layout_width="186dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:ems="10" 
      android:inputType="number" 
      android:hint="Account Type" 
      android:textColorHint="@color/menucolor" 
      android:layout_weight="0.05" /> 

     <EditText 
      android:id="@+id/txtechecktype" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="5dp" 
      android:layout_marginTop="10dp" 
      android:layout_weight="0.84" 
      android:ems="10" 
      android:hint="E-Check Type" 
      android:inputType="number" 
      android:textColorHint="@color/menucolor" /> 

    </LinearLayout> 




</RelativeLayout> 
</ScrollView> 

Payment.java

public class Payment extends AppCompatActivity { 

EditText paymentAmount, paymentDateMonth, paymentDateYear, creditCardNumber, expiryDateMonth, 
    expirydateYear, ccv, firstName, lastName, address, city, state, zipCode, county, 
    abaRoutingNumber, accountNumber, bankName, accountName, accountType, echeckType; 

RadioGroup radioGroup1; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_payment); 

    paymentAmount = (EditText) findViewById(R.id.txtpaymentamount); 
    paymentDateMonth = (EditText) findViewById(R.id.txtpaymentmonth); 
    paymentDateYear = (EditText) findViewById(R.id.txtpaymentyear); 

    //creadit card 
    creditCardNumber = (EditText) findViewById(R.id.txtcreaditcardnumber); 
    expiryDateMonth = (EditText) findViewById(R.id.txtexpirymonth); 
    expirydateYear = (EditText) findViewById(R.id.txtexpiryyear); 
    ccv = (EditText) findViewById(R.id.txtccv); 
    firstName = (EditText) findViewById(R.id.txtfirstname); 
    lastName = (EditText) findViewById(R.id.txtlname); 
    address = (EditText) findViewById(R.id.txtaddress); 
    city = (EditText) findViewById(R.id.txtcity); 
    state = (EditText) findViewById(R.id.txtstate); 
    zipCode = (EditText) findViewById(R.id.txtzipcode); 
    county = (EditText) findViewById(R.id.txtcountry); 

    //E-check 
    abaRoutingNumber = (EditText) findViewById(R.id.txtabaroutingnumber); 
    accountNumber = (EditText) findViewById(R.id.txtaccountnumber); 
    bankName = (EditText) findViewById(R.id.txtbankname); 
    accountName = (EditText) findViewById(R.id.txtaccountname); 
    accountType = (EditText) findViewById(R.id.txtaccounttype); 
    echeckType = (EditText) findViewById(R.id.txtechecktype); 

    radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1); 

    radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
     @Override 
     public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) { 
      if (checkedId == R.id.rdocreditcard){ 
       creditCardNumber.setVisibility(View.VISIBLE); 
       expiryDateMonth.setVisibility(View.VISIBLE); 
       expirydateYear.setVisibility(View.VISIBLE); 
       ccv.setVisibility(View.VISIBLE); 
       firstName.setVisibility(View.VISIBLE); 
       lastName.setVisibility(View.VISIBLE); 
       address.setVisibility(View.VISIBLE); 
       city.setVisibility(View.VISIBLE); 
       state.setVisibility(View.VISIBLE); 
       zipCode.setVisibility(View.VISIBLE); 
       county.setVisibility(View.VISIBLE); 

       abaRoutingNumber.setVisibility(View.INVISIBLE); 
       accountNumber.setVisibility(View.INVISIBLE); 
       bankName.setVisibility(View.INVISIBLE); 
       accountName.setVisibility(View.INVISIBLE); 
       accountType.setVisibility(View.INVISIBLE); 
       echeckType.setVisibility(View.INVISIBLE); 
      } 
      else { 
       creditCardNumber.setVisibility(View.INVISIBLE); 
       expiryDateMonth.setVisibility(View.INVISIBLE); 
       expirydateYear.setVisibility(View.INVISIBLE); 
       ccv.setVisibility(View.INVISIBLE); 
       firstName.setVisibility(View.INVISIBLE); 
       lastName.setVisibility(View.INVISIBLE); 
       address.setVisibility(View.INVISIBLE); 
       city.setVisibility(View.INVISIBLE); 
       state.setVisibility(View.INVISIBLE); 
       zipCode.setVisibility(View.INVISIBLE); 
       county.setVisibility(View.INVISIBLE); 

       abaRoutingNumber.setVisibility(View.VISIBLE); 
       accountNumber.setVisibility(View.VISIBLE); 
       bankName.setVisibility(View.VISIBLE); 
       accountName.setVisibility(View.VISIBLE); 
       accountType.setVisibility(View.VISIBLE); 
       echeckType.setVisibility(View.VISIBLE); 



      } 
     } 
    }); 

} 

}

+0

你應該在相同的地方實現兩個佈局,並根據單選按鈕單擊 – sumit

回答

1

不知道人們爲什麼給你這麼愚蠢的答案。 試試這個簡單的事情:

在你的佈局代碼更改此:

只需在下面的單選按鈕佈局做兩個佈局是這樣的:

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_alignStart="@+id/linearLayout4" 
      android:layout_below="@+id/linearLayout4" 
      android:layout_alignEnd="@+id/linearLayout4" 
      android:id="@+id/creditcard_layout"> 
//copy your credit card layout here 
</LinearLayout> 
<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:visibility="gone" 
      android:layout_alignEnd="@+id/linearLayout4" 
      android:layout_alignStart="@+id/linearLayout4" 
      android:layout_below="@+id/linearLayout4" 
      android:id="@+id/echeck_layout"> 

//copy your ecard card layout here 
</LinearLayout> 

,然後在你的代碼單選按鈕點擊查看各自的佈局。除此之外,您不必改變其他任何東西。

希望它能幫助你。

+0

工作的可見性設置!非常感謝 – TheSwiftGuy77

-1

您應該查看屬性View.GONEView.VISIBLE玩盡佈局出現/消失正確。

-1

您可以在RelativeLayout中使用兩個FrameLayout。將第一個&其他信用卡相關的所有視圖插入第二個FrameLayout。然後單擊管理與事件和View.GONEView.VISIBLE

0

使用View.GONE而不是View.INVISIBLE

View.INVISIBLE:

這種觀點是無形的,但它仍然佔用空間佈局 目的。

View.GONE:

這種觀點是不可見的,並且它不承擔佈局 目的的任何空間。

相關問題