2013-11-01 1 views
2

나는 이미지와 두 개의 텍스트 뷰가있는 상대 레이아웃이 있습니다 (뉴스 제목과 다른 하나는 날짜). 제목과 함께 textview의 너비에 대한 하드 코드 된 값을 넣습니다. 랩 내용을 사용하면 날짜가 겹칩니다. 그것은 다음과 같습니다안드로이드 - 이미지와 텍스트, 디자인 문제가있는 RelativeLayout

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:padding="5dp" > 

<LinearLayout 
    android:id="@+id/thumbnail" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_marginRight="5dp" 
    android:padding="3dp" > 

    <ImageView 
     android:id="@+id/imgIcon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/internet" 
     android:contentDescription="News" /> 
</LinearLayout> 

<TextView 
    android:id="@+id/txtTitle" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/thumbnail" 
    android:layout_toRightOf="@+id/thumbnail" 
    android:text="Timberlake's fourth studio album The 20/20 Experience – 2 of 2 was released on September 30, 2013." 
    android:textSize="14sp" /> 

<TextView 
    android:id="@+id/txtDate" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@+id/txtTitle" 
    android:layout_marginRight="5dp" 
    android:gravity="right" 
    android:text="23.09.2013" 
    android:textColor="#C0C0C0" 
    android:textSize="10sp" /> 

</RelativeLayout> 

화면 크기 4,7의 경우 :

screen size 4,7

을하지만 화면 크기 5,1 나쁜 같습니다

여기 내 XML 코드의

screen size 5,1

내 목표는 tha입니다. t 각 화면 크기에 동일한 모양이 있습니다. 제목과 날짜 사이의 공백은 항상 같아야합니다. 어떻게해야합니까?

+1

'sp' 대신에 textsizes에'dp'를 사용합니까? –

+0

변경했지만 아무런 차이가 없습니다 –

답변

2

이미 RelativeLayout을 사용하고 있습니다. 놀랍게도 빠른 해결 방법이 있습니다. TextView의 너비를 match_parent으로 남겨주세요.하지만 원하는 것은 ImageViewTextView 사이에 샌드위치를 ​​넣는 것입니다. 다음 작업을 수행하십시오 (이 작업을 수행하려면 레이아웃에서 TextViews의 순서를 전환해야 함).

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:padding="5dp" > 

    <LinearLayout 
     android:id="@+id/thumbnail" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginRight="5dp" 
     android:padding="3dp" > 

      <ImageView 
       android:id="@+id/imgIcon" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="News" /> 
    </LinearLayout> 

    <!-- Note: I switched txtDate and txtTitle in your layout file ONLY --> 
    <!-- This will NOT change their order in your actual view   --> 
    <TextView 
     android:id="@+id/txtDate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignTop="@+id/txtTitle" 
     android:layout_marginRight="5dp" 
     android:gravity="right" 
     android:text="23.09.2013" 
     android:textColor="#C0C0C0" 
     android:textSize="10sp" /> 

    <!-- This is the important part, note the android:layout_toLeftOf --> 
    <!-- Also remember to change the width back to "wrap_content --> 
    <TextView 
     android:id="@+id/txtTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/thumbnail" 
     android:layout_toRightOf="@+id/thumbnail" 
     android:layout_toLeftOf="@id/txtDate" 
     android:text="Timberlake's fourth studio album The 20/20 Experience – 2 of 2 was released on September 30, 2013." 
     android:textSize="14sp" /> 

</RelativeLayout> 

이렇게하면 원하는보기가 제공됩니다.

희망이 도움이됩니다. 행운과 행복을위한 코딩!

+0

고마워요! 레이아웃 파일에서 작동하지만 앱을 컴파일하면 주문이 변경됩니다. 매우 혼란 스럽네요. –

+0

어떻게 그렇게됩니까? 데이트가 먼저오고 그 다음에 설명이 올까요? –

+0

예. 내 활동에서 뭔가를 바꿔야합니까? –

관련 문제