2016-08-19 2 views
0

현재 Android에서 앱을 만들고 있는데 해결 방법을 찾을 수없는 RelativeLayout과 관련된 특정 문제에 봉착했습니다.두보기 간의 상대 위치보기

나는 레이아웃에이 세 가지보기를 다음과 같이

enter image description here

중간에 텍스트 뷰가 충실해야 : 텍스트 뷰, 텍스트 뷰와 이미지 뷰 (수평 배치는), 여기에 IOS 대응의 스크린 샷입니다 첫 번째는 Imageview에 도착할 때까지 최소 크기 (줄 바꿈)를 유지하면서 첫 번째 Textview는 잘립니다.

IOS에서는이 작업을 수행하기 위해 제한 조건에 우선 순위를 설정했지만 Android에서이 문제를 해결하는 방법을 알 수는 없습니다.

<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:background="@drawable/daily_movie_title_box"> 

    <TextView 
    android:id="@+id/daily_header_textview" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 


    android:padding="15dp" 
    android:text="New Text aawi oa ioawfwi" 
    android:textSize="16sp" 

    android:textStyle="bold" 
    android:textColor="@color/white" 

    android:lines="1" 
    android:singleLine="true" 

    android:layout_alignParentStart="true" 
    /> 


    <TextView 
    android:id="@+id/duration_text" 
    android:text="138 mins" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:textSize="13sp" 
    android:textColor="@color/white" 
    android:lines="1" 
    android:layout_alignBaseline="@id/daily_header_textview" 

    android:layout_toStartOf="@+id/certification_icon" 
    android:layout_toEndOf="@id/daily_header_textview" 

    /> 

    <ImageView 
    android:id="@id/certification_icon" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentEnd="true" 
    android:src="@drawable/uk12a" 
    android:layout_alignBottom="@id/daily_header_textview" 
    app:layout_aspectRatio="100%"/> 

</android.support.percent.PercentRelativeLayout> 

(내가 원하는 인)이 결과 어떤 : 내가 뭘하려 여기

enter image description here

그러나 나는 내가 같이 행동 아니에요 최초의 텍스트 뷰의 텍스트를 높일 때 욕망 ...

enter image description here

Android에서 원하는 동작을 달성 할 수 있습니까 (중간 Textview 랩 콘텐츠를 유지하고 필요에 따라 첫 번째 텍스트를 자릅니다)?

결국 솔루션을 찾으면 업데이트를 게시하고 누군가가이 동작을 수행하는 쉬운 방법을 찾을 수 있는지 알고 싶습니다. 의심되는 부분입니다.

감사합니다.

+0

모든보기의 너비를 "0dp"로 설정하고 각보기의 비율 값 (예 : 첫 번째보기 5, 다음 2 및 마지막보기 1)과 관련된 layout_weight 속성을 사용할 수 있습니다. 이것이 당신이 찾고있는 것인지 확실하지 않습니다. – TSGames

+0

dp의 첫 번째 TextView에 고정 된 layout_width를 정의하십시오. –

+0

하지만 첫 번째 Textview의 너비를 동적으로 지정하여 사용할 수있는 공간이 없으면 내용을 줄이면됩니다.이 경우에는 잘립니다. 이유는 중간 Textview가 첫 번째 끝 부분에 있기를 원합니다. 현재 시나리오에서는 중간 텍스트가 잘립니다. – Nadav96

답변

1

, 당신은 첫 번째 TextView은 가능한 한 크게 할 것을 권장합니다 다음을 사용하여 각 구성 요소 (화면 공간의 양)에 대한 가중치를 부여 할 수 있습니다 너무 작다. 두 번째 TextViewwrap_content이어야하지만 행이 없을 때 나머지 부모 레이아웃을 채워야합니다. ImageViewwrap_content으로 설정됩니다.

나는이 레이아웃과 테스트 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:shrinkColumns="0" 
     android:stretchColumns="1"> 

     <TableRow> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:singleLine="true" 
       android:text="Shrinking text dddddddddddddddddddddd"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Midle column"/> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@mipmap/ic_launcher"/> 
     </TableRow> 

    </TableLayout> 

</LinearLayout> 

유일한 문제는 두 번째 열은 매우 큰 텍스트가있는 경우, 그 부모에서 다른보기를 밀어 것입니다. 그러나 귀하의 경우, 나는 이것이 문제가 될 것이라고 생각하지 않습니다. 그렇지 않으면, 나는 그것이 일을한다고 생각합니다.

+0

예! 내가 원했던대로 정확하게 행동하는 것 같습니다 (중간 텍스트는 너무 길지 않아야합니다). 감사합니다 :) – Nadav96

0

이 어떤 제안 된 솔루션은 다음과 같습니다

  • 당신은 각 구성 요소 (TextViewsImageView)에 대한 수평 방향으로 무게와 LinearLayout를 사용할 수 있습니다.
  • 두 번째 TextView의 최소 및 최대 텍스트 길이를 설정할 수 있습니다.

하지만 첫 번째 해결 방법을 선호합니다. 텍스트의 경우 텍스트 뒤에 공간을 추가하지 않고,

나의 이해에서
android:layout_height 
+0

그래, 이해하지만 첫 번째 방법을 사용하면 첫 번째 Textview의 폭이 텍스트 내부에 관계없이 정적이됩니다. 중간 텍스트 뷰를 첫 번째 텍스트 끝 부분에 정렬하려고하므로 동일한 줄에있는 것처럼 보입니다. 두 번째 방법을 이미 시도했지만 다른 제약 조건 (toStartOf, toEndOf)을 설정하면 레이아웃에서이 속성을 무시하는 것으로 보입니다. – Nadav96

관련 문제