2017-04-26 1 views
0

나는 이것보다 약간 새로운 편이어서 간단하다면 사과드립니다. 나는 2x4 크기의 GridLayout을 가지고 있으며 클릭 할 수있는 이미지, 이미지가 바뀌고 사운드가 재생된다.클릭 할 수있는 이미지 뷰 위에 Seekbar

각 이미지 상단에 볼륨 컨트롤을 추가하여 해당 이미지 노이즈 볼륨을 제어하고 싶습니다. 어떻게해야합니까?

<GridLayout 
     android:id="@+id/mainGrid" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:background="@color/colorPrimary" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent"> 

     <ImageView 
      android:id="@+id/whitenoise" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="0" 
      android:layout_columnWeight="1" 
      android:layout_gravity="fill" 
      android:layout_row="0" 
      android:layout_rowWeight="1" 
      android:adjustViewBounds="true" 
      android:background="@android:color/transparent" 
      android:onClick="whiteNoiseTapped" 
      android:scaleType="fitXY" 
      android:text="White 1" 
      app:srcCompat="@drawable/whitenoise" /> 

답변

0
Use FrameLayout for this. 

<FrameLayout> 

<ImageView> 
android:id="@+id/whitenoise" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="0" 
      android:layout_columnWeight="1" 
      android:layout_gravity="fill" 
      android:layout_row="0" 
      android:layout_rowWeight="1" 
      android:adjustViewBounds="true" 
      android:background="@android:color/transparent" 
      android:onClick="whiteNoiseTapped" 
      android:scaleType="fitXY" 
      android:text="White 1" 
      app:srcCompat="@drawable/whitenoise" 
<ImageView> 

<Button > 
</Button> 

</FrameLayout> 
+0

감사합니다. 그런 다음 해당 FrameLayout 태그 안에 모든 ImageView를 넣을 수 있습니까? – AndyCr15

+0

방금 ​​이걸 시도해 보았습니다. 그 코드는 모든 종류의 오류를줍니다 ...? '레이아웃 높이를 정의해야합니다' – AndyCr15

+0

프레임 레이아웃의 높이와 너비를 설정하고 버튼을 버튼 태그 안에 넣으십시오. –

0

당신은 또한 다음과 같은 방법을

layout.xml to some extent like this... 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
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" 
android:background="#000" 
tools:context="com.example.tistis.myapplication.MainActivity"> 

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:numColumns="2" 
    android:verticalSpacing="10dp" 
    android:horizontalSpacing="10dp" 
    android:stretchMode="columnWidth" 
    android:gravity="center" 

    /> 

하고 ImageAdapter.java

을 다음과 같이 할 수있는 일은 코드입니다. 어댑터에서 코드를 작성하는 것은 더러운 방법이므로보기가 부풀려 져야합니다.

class ImageAdapter extends BaseAdapter { 
     private Context mContext; 

     public int screenHeight,screenWidth; 
     public ImageAdapter(Context c) { 
      mContext = c; 
      DisplayMetrics displaymetrics = new DisplayMetrics(); 
      ((Activity)c).getWindowManager(). 
       getDefaultDisplay().getMetrics(displaymetrics); 
      screenHeight = displaymetrics.heightPixels; 
      screenWidth = displaymetrics.widthPixels; 
     } 

     public int getCount() { 
      return mThumbIds.length; 
     } 

     public Object getItem(int position) { 
      return null; 
     } 

     public long getItemId(int position) { 
      return 0; 
     } 


     public View getView(final int position, 
     View convertView, ViewGroup parent) { 
      ImageView imageView=null; 
      RelativeLayout frm; 
      SeekBar seekBar=null; 
      if (convertView == null) { 
       // if it's not recycled, initialize some attributes 
       frm= new RelativeLayout(mContext); 
       frm.setLayoutParams(new GridView.LayoutParams(screenWidth/2-(8*2+10),screenWidth/2-(8*2+10))); 
       frm.setPadding(8, 8, 8, 8); 
       frm.setBackgroundColor(Color.BLACK); 

       imageView = new ImageView(mContext); 
       imageView.setLayoutParams(
       new FrameLayout.LayoutParams(
         RelativeLayout.LayoutParams.MATCH_PARENT, 
         RelativeLayout.LayoutParams.MATCH_PARENT)); 
       imageView.setScaleType(ImageView.ScaleType.FIT_XY); 
       imageView.setBackgroundColor(Color.BLACK); 
       frm.addView(imageView); 

       imageView.setOnClickListener(
        new View.OnClickListener() { 
        @Override 
        public void onClick(View view) { 
         Toast.makeText(mContext, 
         "Item position "+(position+1), 
         Toast.LENGTH_SHORT).show(); 
        } 
       }); 


       seekBar=new SeekBar(mContext); 

       seekBar.setLayoutParams(
       new RelativeLayout.LayoutParams(
       RelativeLayout.LayoutParams.MATCH_PARENT, 40)); 
       RelativeLayout.LayoutParams lp= 
      (RelativeLayout.LayoutParams) 
       seekBar.getLayoutParams(); 
       lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
       seekBar.setMax(15); 
    //  seekBar.setIndeterminate(true); 

       ShapeDrawable thumb = 
       new ShapeDrawable(new OvalShape()); 

       thumb.setIntrinsicHeight(80); 
       thumb.setIntrinsicWidth(30); 
       seekBar.setThumb(thumb); 
       seekBar.setProgress(1); 
       seekBar.setVisibility(View.VISIBLE); 
       seekBar.setBackgroundColor(Color.TRANSPARENT); 

       frm.addView(seekBar); 

      } else { 
       frm = (RelativeLayout) convertView; 
      } 


      if(imageView!=null) 
       imageView.setImageResource(mThumbIds[position]); 
      return frm; 
     } 

     // references to our images 
     private Integer[] mThumbIds = { 
       R.drawable.superman, R.drawable.superman, 
       R.drawable.superman, R.drawable.superman, 

     }; 
    } 
관련 문제