HorizontalScrollView 내부에 들어갈 수있는 텍스트로 된 클릭 가능한 이미지 버튼 목록을 만들려고합니다. 이미지/콘텐츠는 프로그래밍 방식으로 설정됩니다. 이렇게하는 가장 좋은 방법은 LinearLayout 인 것 같았습니다. 그런 다음 관련 내용을 표시하는보기가 포함 된 일련의 RelativeLayouts가 포함되었습니다. 그러나 각 RelativeLayout 사이에 공간을 확보하는 데 문제가 있습니다. xml에서 여백을 설정했지만 프로그래밍 방식으로는 무시되는 것처럼 보이고 RelativeLayout 객체는 함께 찌그러 뜨 렸습니다.LinearLayout 내부의 연속적인 RelativeLayouts 사이에 공백을 얻으려면 어떻게해야합니까?
일부 코드 :
<RelativeLayout
android:id="@+id/details_image_button"
android:layout_width="75dp"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:background="#00ff78">
<ImageView
android:id="@+id/loadable_image_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:id="@+id/details_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#b083ef"
android:text="PH - Info about title"
android:layout_alignParentBottom="true"
/>
//Code below is looped through several times
RelativeLayout imageButtonLayout = (RelativeLayout) inflater.inflate(R.layout.details_image_button, null);
RelativeLayout.LayoutParams imageButtonLayoutParams = new RelativeLayout.LayoutParams(100, 100);
imageButtonLayoutParams.setMargins(10, 10, 10, 10);
imageButtonLayout.setLayoutParams(imageButtonLayoutParams);
내가 점점 오전 현재 결과는 고체 녹색합니다 (RelativeLayout의 배경 색상)보다는 RelativeLayouts의 그룹과의 예상되는 결과 각 사이의 공간. 각 RelativeLayout간에 마진 또는 버퍼를 가장 효과적으로 얻으려면 어떻게해야합니까? 당신의 RelativeLayout
가 LinearLayout
내부에있는 경우
이것은 실제로 문제를 "해결"하지 않지만, 대신에 "margin"대신에 "padding"을 사용할 수 있습니다. – Shadesblade
나는 부모 컨테이너를 당신의'inflate()'호출로 넘겨주지 않음으로 거의 확실하다. (어떤 inflator가 어떤 LayoutParams를 사용할 지 모르기 때문에 마진을 버릴 것이다. 그래서 ViewGroup으로 돌아 간다. LayoutParams). 널 (null)을 전달하는 대신'inflate (R.layout.details_image_button, parent, false);'(또는 즉시 첨부하려는 경우 true)를 호출하십시오. – kcoppock