2014-07-18 4 views
1

캘린더 앱을 만들려고합니다. 모든 셀이 테두리처럼 보이기를 원합니다.하지만 그 방법을 알아낼 수는 없습니다. 그리드 뷰를 채우는 어댑터안쪽에 테두리가있는 안드로이드 격자보기

public View getView(int position, View convertView, ViewGroup parent) { 
    View v = convertView; 
    TextView dayView; 
    if (convertView == null) { 
     LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     v = vi.inflate(R.layout.calendar_item, null); 
    } 
    v.setLayoutParams(new GridView.LayoutParams((int) Math.ceil((parent.getWidth()/7)), (int) Math.ceil((parent.getWidth()/7)))); 
    dayView = (TextView) v.findViewById(R.id.date); 
    dayView.setText(days[position].toString()); 
    dayView.setBackgroundColor(Color.CYAN); 
    dayView.setPadding(10, 10, 10, 10); 
    dayView.setTextColor(Color.WHITE); 
    if (days[position].getMonth() - 1 != month.get(Calendar.MONTH) || days[position].getYear() != month.get(Calendar.YEAR)) { 
     dayView.setTextColor(Color.rgb(154, 154, 154)); 
    } else { 
     if (days[position].hasEvent()) { 
      if (days[position].getIsSelected()) { 
       v.setBackgroundColor(Color.RED); 
      } else { 
       dayView.setTextColor(Color.BLACK); 
      } 
     } else { 
      if (days[position].getIsSelected()) { 
       dayView.setTextColor(Color.WHITE); 
      } else { 
       dayView.setTextColor(Color.BLACK); 
      } 
     } 
    } 
    return v; 
} 

이것은 calendar_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="0dp" 
    android:layout_height="60dp" 
    android:layout_margin="0dp" 
    android:clickable="false" 
    android:gravity="center" 
    android:orientation="vertical" 
    android:padding="0dp" > 

    <TextView 
     android:id="@+id/date" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:background="@android:color/background_light" 
     android:clickable="false" 
     android:gravity="center" 
     android:textColor="@android:color/white" /> 

</LinearLayout> 

이며,이 그것을 BG 오으로 지금 enter image description here

+0

투명 영역이있는 사용자 정의 테두리 이미지를 모눈 항목 상위 레이아웃으로 설정하십시오. –

+0

레이아웃의 배경으로 설정 한 사용자 정의 모양 만들기 (calendar_item.xml) –

답변

3

첫 번째는 코드 이름 "shape_my_border.xml"와 drawable folder에서 파일 .xml을 만듭니다

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

<!-- Change to the color you want for the background --> 
<solid android:color="@color/white" /> 

<stroke 
    android:width="1dp" 
    android:color="@color/grey_border" /> 
    <!-- Change to the color you want for the border --> 
</shape> 

그런 다음 LinearLayoutandroid:background="@drawable/shape_my_border" 등의 background로 사용.

캘린더의 날짜를 클릭 할 때 배경 또는 테두리를 변경하려면 "shape_my_border.xml"파일을 만든 것과 같은 방법으로 selector 파일을 만들어야하지만 코드를 사용해야합니다 like :

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

<item android:drawable="@drawable/shape_border_2" android:state_selected="true"/> 
<!-- selected --> 
<item android:drawable="@drawable/shape_border_2" android:state_pressed="true"/> 
<!-- pressed --> 
<item android:drawable="@drawable/shape_border_2" android:state_focused="true"/> 
<!-- focused --> 
<item android:drawable="@drawable/shape_border_1"/> 
<!-- default --> 

</selector> 

희망이 있습니다.

1

를 사용하여 같은 모양을 모습입니다 : 여기서 예

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <stroke android:width="2dp" android:color="#FFFFFFFF" /> 
    <gradient android:startColor="#DD000000" android:endColor="#DD2ECCFA" 
      android:angle="225"/> 

    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
    android:topLeftRadius="7dp" android:topRightRadius="7dp"/> 
</shape> 

하고 그 결과를 확인하기 위해 텍스트 뷰로부터 BG 제거

(하여 케이스의 LinearLayout)에서 셀 항목 F.

희망이 있습니다.

+0

어디에서이 XML을 만드나요? drawable에서 시도한 다음 calendar_item.xml의 배경으로 사용했지만 아무 일도 일어나지 않습니다. –

+0

tv bg를 제거 했습니까? – AlexBalo