Ich habe ein kleines Problem.Wie TextView mit Hintergrund im Layout ausrichten - Android
Ich habe:
Ich möchte: (aber der Text einige dp von links)
Ist es möglich? Hier ist ein ganzer Code meines Layouts: (@ + id/txtName ist die Textview aus dem Screenshot!)
<?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"
android:background="@color/md_brown_100"
android:orientation="vertical"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="10dp" >
<LinearLayout android:id="@+id/list_offer_item_container"
android:layout_width="150dp"
android:layout_height="150dp"
android:background="@drawable/shape"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center_vertical">
<TextView android:id="@+id/list_offer_badge_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/list_offer_item_container"
android:textColor="@color/md_amber_700"
android:textSize="12sp"
android:visibility="gone"
android:text=""/>
</LinearLayout>
<LinearLayout
android:layout_height="150dp"
android:orientation="vertical"
android:padding="5dp"
android:weightSum="1"
android:layout_width="150dp">
<ImageView
android:id="@+id/imgcreditcompany"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal"
android:layout_above="@+id/txtname"
android:contentDescription="@string/app_name"
android:layout_height="48dp"
android:layout_width="48dp" />
<TextView
android:id="@+id/txtname"
android:gravity="center_vertical"
android:background="@drawable/ic_dollar_ss"
android:layout_height="30dp"
android:layout_marginTop="5dp"
android:textColor="@color/AliceBlue"
android:textSize="18sp"
android:text="Name"
android:textAllCaps="false"
android:textStyle="normal|bold"
android:layout_width="153dp" />
<TextView
android:id="@+id/txtdesc"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="1dp"
android:maxLines="3"
android:textColor="#80869c"
android:textSize="@dimen/textsizeearncredit_desc"
android:text="This is a description of the offer and this is just a demo to show off 3 lines stacking correctly on top of each other"
android:layout_weight="0.55"
android:layout_width="140dp" />
</LinearLayout>
<ImageView
android:id="@+id/nextArrow"
android:layout_alignParentRight="true"
android:tint="@color/md_grey_300"
android:rotation="180"
android:layout_width="32dp"
android:visibility="gone"
android:layout_marginRight="16dp"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_height="32dp"
android:contentDescription="@string/app_name"
android:padding="@dimen/two" />
</LinearLayout>
</RelativeLayout>
Bitte helfen Sie uns, Jungen! Vielen Dank. Du kannst mir eine Idee davon geben. Prost!
Große Lösung! Danke, aber wie schafft man den Hintergrund an dem Ort, den ich will, und den Text ein paar dp von der linken Grenze? –
Überprüfen Sie den Kommentar über –
Sie können hinzufügen, 'android: paddingStart' zu Ihrem LinearLayout und legen Sie fest, wie viele DP Sie möchten, dass es vom linken Rand entfernt. Beachten Sie, dass Sie das ursprüngliche Ergebnis erhalten, wenn Sie es auf 5dp setzen. Was passiert mit dem Hintergrund? –