2016-08-09 30 views
-1

Ich weiß, es gibt viele Threads mit mehr oder weniger gleichen Thema, aber keiner von ihnen deckt meine Situation:Wie wird das Bildsymbol in einem linearen Layout ausgerichtet?

Ich habe ein wenig Mülleimer für die Schaltfläche löschen, aber es verschwindet immer vom Bildschirm, wenn die Zeile des Textes ist zu lang und wenn es zu kurz ist es an der Linie befestigt und ich wollte nur auf der rechten Seite der App wie der Add_item Button sein, aber da es in einem linearen Layout ist, funktioniert es nicht

ativity_main .xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
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="com.example.owner.test24.MainActivity"> 

<TextView 
    android:id="@+id/header" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/header" 
    android:gravity="center_vertical" 
    android:textColor="@color/accent" 
    android:textSize="24sp" /> 
<ImageButton 
    android:id="@+id/add_item" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@android:color/transparent" 
    android:layout_alignEnd="@+id/header" 
    android:layout_alignRight="@+id/header" 
    android:src="@drawable/add_item_button" 
    android:contentDescription="@string/add_item"/> 
<ListView 
    android:id="@+id/todo_list" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/header"/> 

</RelativeLayout> 

to_do_item_layout.xml

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

<CheckBox 
    android:id="@+id/checkBox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:id="@+id/item" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="20sp"/> 

<ImageButton 
    android:id="@+id/btnDel" 
    android:src="@drawable/ic_delete_button" 
    android:background="@android:color/transparent" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Delete" 
    /> 

wenn jemand Lösung hat lass es mich wissen.

Antwort

0
use it, it works on every screen size 

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical" 
    android:weightSum="1"> 

    <CheckBox 
     android:id="@+id/checkBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.03"/> 

    <TextView 
     android:id="@+id/item" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="hhhhh" 
     android:gravity="center_horizontal" 
     android:textSize="20sp" 
     android:layout_weight="0.87"/> 

    <ImageButton 
     android:id="@+id/btnDel" 
     android:src="@drawable/delete_icon" 
     android:background="@android:color/transparent" 
     android:layout_width="wrap_content" 
     android:layout_gravity="end|center_vertical" 
     android:layout_height="wrap_content" 
     android:text="Delete" 
     android:layout_weight="0.1" /> 
    </LinearLayout> 
+0

@ M.Bill, wenn es funktioniert bitte upvote – shahid17june

+0

Warum muss ich Gewicht für alle Ansichten hinzufügen, wie Checkbox und ImageButton Breite sind fast in der Größe fixiert? –

+0

Ich wusste es. Aber ist es notwendig für eine feste Ansicht? Ich kann das hinzufügen, wenn alle Ansichten Breite dynamisch sind. –

0

layout_gravity Tag

android:layout_gravity="right" 
2

Versuchen unter einem

<TextView 
    android:id="@+id/item" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textSize="20sp"/> 

hinzufügen Hofft es Ihr Problem zu lösen. :)

+0

dank es –

+0

Willkommen funktioniert. Wenn Sie die Antwort akzeptieren, wird es anderen helfen. :) –

0

Gebrauch Gewicht:

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

<CheckBox 
android:id="@+id/checkBox" 
android:layout_width="0dip" 
android:layout_height="wrap_content" 
amdroid: layout_weight="0.2" 
/> 

<ImageButton 
android:id="@+id/btnDel" 
android:src="@drawable/ic_delete_button" 
android:background="@android:color/transparent" 
android:layout_width="0dip" 
android:layout_height="wrap_content" 
android:text="Delete" 
amdroid: layout_weight="0.2" 
/>