툴바에서 버튼을 클릭 할 때 버튼의 가시성을 토글하는 툴바를 만듭니다. 따라서 사용자가 "그리기"버튼을 클릭하면 보이지 않는 버튼 "연필"과 "펜"이 "그리기"버튼 위에 표시됩니다. "그리기"버튼을 다시 클릭하면 "연필"과 "펜" 다시 보이지 않게됩니다.Android에서 버튼 가시성 문제가 발생했습니다.
을 내 xml 파일 내에서 내가 어떤 버튼의 공개 설정이 나는 그들이 볼 수 없습니다 활동을 시작할 때 이렇게.이 부분은 정직 "보이지 않는"로 설정했습니다.
을 btnDrawLine의 .XML 파일 - (12시 21분 @ 업데이트)
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="fill_parent" > <com.odhranlynch.testSection.UserInterface android:id="@+id/UserInterface" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" /> <Button android:id="@+id/btnDraw" android:layout_width="80dip" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:text="Draw" /> <Button android:id="@+id/btnDrawLine" android:layout_width="80dip" android:layout_height="wrap_content" android:layout_above="@+id/btnDraw" android:layout_alignParentLeft="true" android:visibility="visible" android:text="Line" /> <Button android:id="@+id/btnDrawCurve" android:layout_width="80dip" android:layout_height="wrap_content" android:layout_above="@+id/btnDrawLine" android:layout_alignParentLeft="true" android:visibility="visible" android:text="Curve" /> <Button android:id="@+id/btnCutout" android:layout_width="80dip" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_toRightOf="@+id/btnDraw" android:text="Cutout" /> <Button android:id="@+id/btnCutInner" android:layout_width="80dip" android:layout_height="wrap_content" android:layout_above="@+id/btnDraw" android:layout_toRightOf="@+id/btnDraw" android:visibility="visible" android:text="Inner" /> <Button android:id="@+id/btnCutOutter" android:layout_width="80dip" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/btnDrawCurve" android:layout_alignBottom="@+id/btnDrawCurve" android:layout_toLeftOf="@+id/btnCancel" android:visibility="visible" android:text="Outter" /> <Button android:id="@+id/btnCancel" android:layout_width="80dip" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_toLeftOf="@+id/btnFinish" android:text="Cancel" /> <Button android:id="@+id/btnFinish" android:layout_width="80dip" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:text="Finish" /> </RelativeLayout>
다음 사용자가 볼 수있는 버튼을 클릭하면
, 내가 좋겠 보이지 않는 단추가 나타나는 것처럼.여기에 문제가 있습니다. 다시는 나타나지 않습니다! Lol 나는 그것에 혼란스러워합니다.
누군가가 언급 추가 점으로 친절하게도 나를 위해이에 너무 되거하기 :
testActivity.java
package com.odhranlynch.testSection;
import com.odhranlynch.testSection.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class testActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_product);
// Find buttons and give them a name.
final View btnDraw = findViewById(R.id.btnDraw);
final View btnCutOut = findViewById(R.id.btnCutout);
final View btnDrawLine = findViewById(R.id.btnDrawLine);
final View btnDrawCurve = findViewById(R.id.btnDrawCurve);
final View btnCutInner = findViewById(R.id.btnCutInner);
final View btnCutOutter = findViewById(R.id.btnCutOutter);
//Draw Button clicked (UI Toolbar).
btnDraw.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//Treat button as a toggle button
//So if a sub-button (e.g. Draw Line) is visible, then we know the button has
//been toggled to visible so lets now make it invisible.
if (btnDrawLine.getVisibility()== View.VISIBLE) {
//Its visible.
btnDrawLine.setVisibility(View.INVISIBLE);
btnDrawCurve.setVisibility(View.INVISIBLE);
Log.d("TAG", "INVISIBLE");
} else {
// Either gone or invisible
btnDrawLine.setVisibility(View.VISIBLE);
btnDrawCurve.setVisibility(View.VISIBLE);
Log.d("TAG", "VISIBLE");
}
}
});
}
}
될 경우 내가 만약 내가 매우 감사하게 될 것입니다 .xml 파일 내에서 볼 수 있도록 버튼의 가시성을 설정하십시오. 런타임 중에 visibilty를 완벽하게 전환 할 수 있습니다!
다시 말하지만, 나는 도움 :)의 감사 드리겠습니다 귀하의 코드가 잘 작동
예상대로 로그 메시지를 인쇄하고 있습니까? Visible, Invsible, Visible .. 등 각 단추 시계에? –
맞아요, 토글 버튼이 작동하는지 확실히 압니다. – Odhran
흠, btnDrawCurve.setVisibility (View.INVISIBLE)를 View.GONE으로 대체 해 보셨습니까? 그냥 큰소리로 생각해. –