0

Ich arbeite an einer App, wo ich eine Fortschrittsleiste und eine Textansicht haben möchte. Und die Sache ist, dass die Textansicht einen anderen Hintergrund haben sollte. Wenn ich android:layout_width="match_parent" verwende, bleibt Platz an den Seiten der Textansicht. Wenn wir einen weißen Hintergrund haben, ist es in Ordnung, aber wenn wir einen anderen Hintergrund verwenden, sieht es nicht gut aus. Wie kann ich das erreichen?Wie wird ein TextView hinzugefügt, das die volle Breite des Layouts des Telefons einnimmt?

Kurz gesagt, bekomme ich die folgende Ansicht (erstes Bild), wenn ich setze, aber ich möchte, dass die Seite wie die im zweiten Bild aussieht.

When I add match_parentThis is how I want the UI to be

activity_main.xml

<?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: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="senti.com.freelaneprogress.MainActivity"> 

    <ProgressBar 
     android:id="@+id/progressBar" 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_width="300dp" 
     android:layout_height="300dp" 
     android:layout_centerInParent="true" 
     android:max="100" 
     android:progress="40" 
     android:rotation="270" 
     android:progressDrawable="@drawable/circular"/> 

    <TextView 
     android:id="@+id/eta" 
     android:background="#00000000" 
     android:layout_height="100dp" 
     android:layout_width="150dp" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="1.3in"/> 

    <TextView 
     android:layout_width="150dp" 
     android:layout_height="50dp" 
     android:layout_marginTop="2in" 
     android:layout_centerHorizontal="true"/> 

    <TextView 
     android:background="@drawable/textviewbg" 
     android:layout_width="match_parent" 
     android:layout_height="30pt" 
     android:contextClickable="false" 
     android:layout_alignParentBottom="true" 
     android:id="@+id/textView" /> 
</RelativeLayout> 
+0

löschen Polsterung bilden den Hauptbehälter (RelativeLayout), dass die IDE fügt hinzu, wenn Sie die Aktivität erstellen – MikeKeepsOnShine

Antwort

1

Legen Sie für die RelativeLayout-Ansicht paddingLeft, paddingRight und paddingBottom auf 0dp fest. Mit anderen Worten:

<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="0dp" 
    android:paddingLeft="0dp" 
    android:paddingRight="0dp" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="senti.com.freelaneprogress.MainActivity"> 


    ... 
    ... 
</RelativeLayout> 

Dies ist das Minimum, das Sie benötigen, um Ihr gewünschtes Ergebnis zu erzielen. Wenn Sie jedoch absolut sein möchten, können Sie auch das PaddingTop von RelativeLayout auf 0dp setzen.

1

Das Problem ist hier

android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 

das Textview-Matching Elternteil ist. Die Sache ist, der Elternteil stimmt nicht mit der gesamten Elternansicht überein, wegen der Auffüllung. Versuchen Sie, die Polsterung zu entfernen, sollte es funktionieren.

0

Entfernen Sie das gesamte Padding des relativen Layouts. Und wenn du wirklich willst, kannst du es progressbar geben.

<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" 
tools:context="senti.com.freelaneprogress.MainActivity"> 

zur relativen Einstellung Polsterung gibt dem Behälterraum, die Sie nicht möchten, die nicht standardmäßig

Verwandte Themen