я здесь четыре набора кнопок и пустой RelativeLayout
под ними, всякий раз, когда я нажимаю одну из них другой макет будет Выдвижной в пустой RelativeLayout
, содержащий еще два набора кнопок, а именно ON и OFF. моя проблема возникает в ON и OFF кнопок, потому что Я хочу ImageView
появляться всякий раз, когда я нажимаю ON кнопку & исчезает всякий раз, когда я нажимаю на кнопку OFF. Вот мой макет и код:Управление в ImageView с помощью кнопки мыши
Это расположение для 4 кнопок:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/green_bg"
tools:context=".AleccMainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/please_choose"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#CAFFD8" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:background="#95FF4F" >
<Button
android:id="@+id/btnAcu"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/tab_acu"
android:onClick="gotoACU" />
<Button
android:id="@+id/btnFan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/tab_fan"
android:onClick="gotoFan" />
<Button
android:id="@+id/btnLight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/tab_light"
android:onClick="gotoLight" />
<Button
android:id="@+id/btnHallway"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/tab_hallway"
android:onClick="gotoHallway" />
</LinearLayout>
<RelativeLayout
android:id="@+id/rl"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/linearLayout" >
</RelativeLayout>
</RelativeLayout>
И это код для одного макета, который будет появляться при нажатии одной из этих четырех (они имеют одни и те же кнопки внутри, но разные изображения, чтобы показать):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/green_bg"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="offFAN"
android:text="@string/off" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:onClick="onFAN"
android:text="@string/on" />
</LinearLayout>
<ImageView
android:id="@+id/fanOn"
android:layout_below="@+id/linearLayout1"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:contentDescription="@string/acu"
android:visibility="invisible"
android:src="@drawable/fan_on" />
</RelativeLayout>
Это одна функция при вызове макета с ON и OFF кнопки:
public void gotoFan(View v){
// Do something in response to button
RelativeLayout rlFAN = (RelativeLayout) findViewById(R.id.rl);
getLayoutInflater().inflate(R.layout.alecc_fan, rlFAN, true);
}
И это то, где я думаю, что моя проблема существует:
public void offFAN (View view) {
String messageToSend = "FANS OFF";
SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
Toast.makeText(AleccMainActivity.this,"Electric Fans turned OFF", Toast.LENGTH_SHORT).show();
ImageView fanON = (ImageView) findViewById(R.id.fanOn);
fanON.setVisibility(View.GONE);
}
public void onLIGHT (View view) {
String messageToSend = "LIGHTS ON";
SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);
Toast.makeText(AleccMainActivity.this,"Flourescent Lights turned ON", Toast.LENGTH_SHORT).show();
ImageView lightON = (ImageView) findViewById(R.id.lightOn);
lightON.setVisibility(ImageView.VISIBLE);
}
Я не могу заставить его работать. Когда я сначала нажимаю на одну из 4 кнопок, тогда нажмите . ON/OFF кажется хорошо, но каждый раз, когда я нажимаю другое изображение, становится больше не видимым.
нет ответа. : \ –