2017-01-19 9 views
0

ImageViewがTextViewの右に揃えられています。テキストが長すぎると、イメージのサイズが変更されます...イメージのサイズを同じにして、TextViewを新しい行に挿入するにはどうすればよいですか?RelativeLayout内でImageViewを修正できません

ショートテキスト、良いサイズ:
enter image description here

ロングテキスト、悪いサイズ:
enter image description here

ここではXMLです:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:background="@color/md_white_1000" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <RelativeLayout 
     android:id="@+id/btn_container_1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:background="@color/blue" 
     android:layout_weight=".50" 
     android:layout_marginRight="1dp"> 

     <Button 
      android:id="@+id/btn_1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:alpha="0" 
      android:onClick="searchClicked"/> 

     <TextView 
      android:id="@+id/btn_text_1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:textColor="@color/md_white_1000" 
      android:paddingEnd="10dp" 
      android:paddingRight="10dp" 
      android:text="BTN1" /> 

     <ImageView 
      android:id="@+id/btn_image_1" 
      android:layout_width="28dp" 
      android:layout_height="28dp" 
      android:layout_centerVertical="true" 
      android:layout_toEndOf="@id/btn_text_1" 
      android:layout_toRightOf="@id/btn_text_1" 
      android:layout_marginTop="2dp" 
      android:layout_marginBottom="2dp" 
      android:src="@drawable/draw" /> 
    </RelativeLayout> 
</LinearLayout> 
+0

tryroid:ellipsize = "end" in Textviewタグ – Onkar

答えて

1

あなたは次のようにこれを行うには、ネストされたリニアレイアウトを追加することができます。

<RelativeLayout 
    android:id="@+id/btn_container_1" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:background="@color/blue" 
    android:layout_weight=".50" 
    android:layout_marginRight="1dp"> 

    <Button 
     android:id="@+id/btn_1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:alpha="0" 
     android:onClick="searchClicked"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     > 

     <TextView 
      android:id="@+id/btn_text_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_gravity="center" 
      android:textColor="@color/md_white_1000" 
      android:paddingEnd="10dp" 
      android:paddingRight="10dp" 
      android:text="BTN1" /> 

     <ImageView 
      android:id="@+id/btn_image_1" 
      android:layout_width="28dp" 
      android:layout_height="28dp" 
      android:layout_gravity="center" 
      android:layout_marginTop="2dp" 
      android:layout_marginBottom="2dp" 
      android:src="@drawable/draw" /> 

    </LinearLayout> 
</RelativeLayout> 
1

私はあなたとリニアレイアウトを使用すべきだと思います相対的なレイアウトの代わりに水平の向きを設定し、textviewとimageviewの両方に重さを設定します。

0

ハードではないコードに任意の属性を行い、画面サイズの変更は、この

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:gravity="center" 
    android:weightSum="1" 
    android:layout_marginTop="100dp" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

     <Button 
      android:id="@+id/btn_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:alpha="0" 
      android:text="button" 
      android:layout_weight="0.2" 
      android:onClick="searchClicked"/> 

     <TextView 
      android:id="@+id/btn_text_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:textColor="@color/colorPrimary" 
      android:layout_weight="0.4" 
      android:text="BTN1" /> 

     <ImageView 
      android:id="@+id/btn_image_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.4" 
      android:src="@drawable/state" /> 
</LinearLayout> 
0
をしようとした場合、それは後の時点で問題を作成します。
Can you try this, if it is not working send me you screen how you want to design.I will help you. 

<?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" 
    tools:context="est.androidapplication.MainActivity"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:background="#00f" 
     android:weightSum="1"> 
     <TextView 
      android:id="@+id/btn_text_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:layout_gravity="center" 
      android:gravity="center" 
      android:textColor="#ff0044" 
      android:paddingEnd="10dp" 
      android:paddingRight="10dp" 
      android:text="BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1BTN1" /> 

     <ImageView 
      android:id="@+id/btn_image_1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:layout_gravity="center" 
      android:gravity="center" 
      android:src="@mipmap/ic_launcher" /> 
    </LinearLayout> 
</RelativeLayout> 
0

リニアレイアウトのtextviewの重みを使用します。

<?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="match_parent"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:layout_margin="10dp" 
    android:layout_centerVertical="true"> 

    <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:text="BTN1"/> 
    <ImageView 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:layout_marginLeft="10dp" 
     android:background="#344"/> 

</LinearLayout> 


</RelativeLayout> 
関連する問題