버튼을 클릭 할 때 다른 레이어를 추가하는 방법

루크

이 버튼 중 하나를 클릭하면 내가 만든 imageView 위에 레이어가 나타나야합니다.

public void onClick(View v) {

    switch(v.getId()){

    case R.id.categoriaA1:

        // add layer a1
        break;

    case R.id.categoriaA2:
        // add layer a2
        break;
    case R.id.categoriaA3:
        //add  layer A3
        break;
    case R.id.categoriaA4:
        // add layer A4
        break;

myAvatar는 내 ImageView입니다. 누군가 나를 도울 수 있습니까?

이것은 내 XML 코드입니다 (4 카테고리에 20 개의 imageButton이 있습니다)

<GridLayout 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:columnCount="1"
android:orientation="vertical"
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.example.settingavatar.MyAvatar" >

<!-- problemi con il dimensionamento -->

<ImageView
    android:id="@+id/anteprimaAvatar"
    android:layout_width="282dp"
    android:layout_height="150dp" 

    android:background="@drawable/btn_background"/>
<!-- griglia che contiene le 4 categorie per i vari oggetti che si possono aggiungere all'avatar -->

<GridLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/anteprimaAvatar"
    android:orientation="vertical" >

    <!-- sottogriglia per la categoria A -->

    <GridLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/categoriaA1"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/cata1"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaA2"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/cata2"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaA3"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/cata3"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaA4"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/cata4"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaA5"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:tag="accessorio" />
    </GridLayout>

    <!-- sottogriglia per la categoria B -->

    <GridLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/categoriaB1"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catb1"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaB2"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catb2"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaB3"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catb3"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaB4"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catb4"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaB5"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:tag="accessorio" />
    </GridLayout>

    <!-- sottogriglia per la categoria C -->

    <GridLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/categoriaC1"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catc1"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaC2"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catc2"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaC3"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catc3"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaC4"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catc4"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaC5"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:tag="accessorio" />
    </GridLayout>

    <!-- sottogriglia per la categoria D -->

    <GridLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/categoriaD1"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catd1"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaD2"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catd2"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaD3"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catd3"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaD4"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:background="@drawable/catd4"
            android:tag="accessorio" />

        <ImageButton
            android:id="@+id/categoriaD5"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:tag="accessorio" />
    </GridLayout>
</GridLayout>

아 디트 야 하리 키샨

레이아웃에 가시성 작업 사용

예를 들어

        LinearLayout lly1 = (LinearLayout)findViewById(R.id.lly1);
        LinearLayout lly2 = (LinearLayout)findViewById(R.id.lly1);
        LinearLayout lly3 = (LinearLayout)findViewById(R.id.lly1);
        LinearLayout lly4 = (LinearLayout)findViewById(R.id.lly1);


  public void onClick(View v) {

switch(v.getId()){

case R.id.categoriaA1:

    // add layer a1
   lly1.setVisibility(v.VISIBLE);
   lly2.setVisibility(v.GONE);
   lly3.setVisibility(v.GONE);
   lly4.setVisibility(v.GONE);
    break;

case R.id.categoriaA2:
    // add layer a2
   lly2.setVisibility(v.VISIBLE);
   lly1.setVisibility(v.GONE);
   lly3.setVisibility(v.GONE);
   lly4.setVisibility(v.GONE);
    break;
case R.id.categoriaA3:
    //add  layer A3
   lly3.setVisibility(v.VISIBLE);
   lly2.setVisibility(v.GONE);
   lly1.setVisibility(v.GONE);
   lly4.setVisibility(v.GONE);
    break;
case R.id.categoriaA4:
    // add layer A4
   lly4.setVisibility(v.VISIBLE);
   lly2.setVisibility(v.GONE);
   lly3.setVisibility(v.GONE);
   lly1.setVisibility(v.GONE);

    break;

}

레이아웃 activity_main.xml에 오는 곳

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/lly1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="visible" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lly2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="gone" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lly3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="gone" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lly4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="gone" >
    </LinearLayout>

</RelativeLayout>

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

버튼을 클릭 할 때 다른 레이어를 추가하는 방법

C #에서 다른 버튼을 클릭 할 때 버튼 클릭 이벤트를 호출하는 방법

wpf에서 버튼을 클릭 할 때 다른 .wav를 재생하는 방법

JavaScript를 사용하여 다른 버튼을 클릭 할 때 버튼을 숨기거나 표시하는 방법

다른 버튼을 클릭할 때 다른 이미지를 표시하는 방법은 무엇입니까?

버튼을 클릭 할 때 FAB 단축 다이얼을 열어 두는 방법

버튼을 클릭할 때마다 다른 "클래스"를 실행하도록 만드는 방법

취소 버튼을 클릭 할 때 다중 삭제를 방지하는 방법

버튼을 클릭할 때마다 스킬바 너비를 줄이는 방법

다른 페이지의 버튼을 클릭할 때 페이지에 div를 만드는 방법

다른 페이지로 이동할 때 버튼 더블 클릭을 차단하는 방법

부트 스트랩에서 라디오 버튼을 클릭 할 때 다른 메뉴를 축소하는 방법

버튼을 여러 번 클릭 할 때 다른 JS 함수를 호출하는 방법은 무엇입니까?

루프에서 tkinter 레이블을 지우는 방법과 다른 버튼을 클릭할 때 루프를 종료하는 방법

버튼을 클릭 할 때 PHP를 실행하는 방법?

다른 프레임을 여는 버튼을 클릭 할 때이 프레임을 다른 프레임과 연결하는 방법은 무엇입니까?-Java

새 버튼을 클릭할 때 다른 모든 div를 닫는 방법은 무엇입니까?

iOS 앱 개발에서 버튼을 클릭 할 때 다른보기를 여는 방법은 무엇입니까?

버튼을 클릭할 때 다른 버튼의 색상을 변경하는 방법은 무엇입니까?

Vue JS - 확인란을 클릭한 다음 버튼을 클릭할 때 사용자 ID를 얻는 방법

버튼을 클릭할 때 collectionView를 새로 고치는 방법

사용자가 버튼을 클릭할 때 페이지 프리로더를 추가하는 방법

행 특정 버튼을 클릭 할 때 데이터베이스에서 가져온 레코드 값을 다른 PHP 페이지로 전달하는 방법

버튼을 클릭 할 때마다 캔버스 개체를 이동하는 방법은 무엇입니까?

jquery에서 버튼을 클릭 할 때마다 입력 값을 추가하는 방법은 무엇입니까?

버튼을 클릭 할 때 스톱워치 타이머를 추가하는 방법은 무엇입니까?

클릭할 때마다 다른 버튼 세트를 표시하는 버튼을 만드는 방법은 무엇입니까?

자바 스크립트, 다른 버튼을 클릭 할 때 다른 것을 나열하는 방법

다시 클릭하거나 다른 곳을 클릭 할 때 부트 스트랩 팝 오버를 닫는 방법

TOP 리스트

  1. 1

    JNDI를 사용하여 Spring Boot에서 다중 데이터 소스 구성

  2. 2

    std :: regex의 일관성없는 동작

  3. 3

    JSoup javax.net.ssl.SSLHandshakeException : <url>과 일치하는 주체 대체 DNS 이름이 없습니다.

  4. 4

    PrematureCloseException : 연결이 너무 일찍 닫혔습니다.

  5. 5

    Xcode10 유효성 검사 : 이미지에 투명성이 없지만 여전히 수락되지 않습니까?

  6. 6

    정점 셰이더에서 카메라에서 개체까지의 XY 거리

  7. 7

    Ionic 2 로더가 적시에 표시되지 않음

  8. 8

    Seaborn에서 축 제목 숨기기

  9. 9

    C #에서 'System.DBNull'형식의 개체를 'System.String'형식으로 캐스팅 할 수 없습니다.

  10. 10

    복사 / 붙여 넣기 비활성화

  11. 11

    ArrayBufferLike의 typescript 정의의 깊은 의미

  12. 12

    Google Play Console에서 '예기치 않은 오류가 발생했습니다. 나중에 다시 시도해주세요. (7100000)'오류를 수정하는 방법은 무엇입니까?

  13. 13

    Kubernetes Horizontal Pod Autoscaler (HPA) 테스트

  14. 14

    jfreecharts에서 x 및 y 축 선을 조정하는 방법

  15. 15

    PRNG 기간보다 순열이 더 많은 목록을 무작위로 섞는 방법은 무엇입니까?

  16. 16

    C # HttpWebRequest 기본 연결이 닫혔습니다. 전송시 예기치 않은 오류가 발생했습니다.

  17. 17

    다음 컨트롤이 추가되었지만 사용할 수 없습니다.

  18. 18

    잘못된 구성 개체입니다. Webpack이 Angular의 API 스키마와 일치하지 않는 구성 개체를 사용하여 초기화되었습니다.

  19. 19

    Android Kotlin은 다른 활동에서 함수를 호출합니다.

  20. 20

    R의 마침표와 숫자 사이에 문자열 삽입

  21. 21

    Assets의 BitmapFactory.decodeStream이 Android 7에서 null을 반환합니다.

뜨겁다태그

보관