2012-07-05 2 views
0

Я пытаюсь добавить 8 текстовых просмотров в моем довольно простом макете. Я хотел бы иметь два текстовых вида на строку и четыре таких строки. Моя задача была выстроена в 2-м, 4-м, 6-м и 8-м текстовых представлениях в этом макете. Текст в виде 1-го, 3-го, 5-го и 7-го текстовых видов имеет разную длину.Несколько текстовых представлений не выравниваются должным образом в Linear Layout

Я не могу выровнять текстовые представления seocnd в каждой строке, которая будет выровнена по вертикали.

В основном, эти виды текста не должны начинаться с одной и той же линии, вертикально, независимо от того, что когда-либо длина первого взгляда текста в этой строке:

может кто-то помочь?

Вот мой XML.

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/productDetailsLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/white" 
android:orientation="vertical" > 

<include 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    layout="@layout/logo_logout" /> 


<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="10dp" > 

    <TextView 
     android:id="@+id/ProductDetailsTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="43dp" 
     android:layout_marginTop="10dp" 
     android:background="@color/Navy" 
     android:gravity="center" 
     android:text="@string/ProductDetailsTitle" 
     android:textColor="@color/white" 
     android:textSize="20dp" 
     android:textStyle="bold" /> 

    <Button 
     android:id="@+id/ProductDetailsEditButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:layout_weight="0.36" 
     android:text="Edit" 
     android:textSize="20dp" /> 
</LinearLayout> 

<include 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dp" 
    layout="@layout/product_details_mainpage_part1" /> 

<include 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dp" 
    layout="@layout/product_details_mainpage_part2" /> 

<include 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dp" 
    layout="@layout/product_details_mainpage_part3" /> 

<include 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dp" 
    layout="@layout/product_details_mainpage_part44" /> 

</LinearLayout> 

ответ

0

Возможно, это может помочь. Вы можете играть с background color и top padding каждого TextView, чтобы сделать это так, как вы хотите. Надеюсь это поможет.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:baselineAligned="false" 
    android:id="@+id/RelativeLayout" 
    android:background="#ffffffff" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout 
     android:id="@+id/background" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

    <TextView 
     android:id="@+id/ProductDetailsTitle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffffff" 
     android:gravity="center" 
     android:paddingTop="50dp" 
     android:text="Hello, I am tired" /> 

    <TextView 
     android:id="@+id/ProductDetailsTitle2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffffff" 
     android:gravity="center" 
     android:paddingTop="50dp" 
     android:text="Hello" /> 

    <TextView 
     android:id="@+id/ProductDetailsTitle3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffffff" 
     android:gravity="center" 
     android:paddingTop="50dp" 
     android:text="Hello" /> 

    <TextView 
     android:id="@+id/ProductDetailsTitle4" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffffff" 
     android:gravity="center" 
     android:paddingTop="50dp" 
     android:text="Hello" /> 
    </LinearLayout> 


    <LinearLayout 
     android:id="@+id/background2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

    <TextView 
     android:id="@+id/ProductDetailsTitle5" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"    
     android:background="#ffffffff" 
     android:paddingTop="50dp" 
     android:gravity="center" 
     android:text="Hello" /> 

    <TextView 
     android:id="@+id/ProductDetailsTitle6" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffffff" 
     android:gravity="center" 
     android:paddingTop="50dp" 
     android:text="Hello" /> 

    <TextView 
     android:id="@+id/ProductDetailsTitle7" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffffff" 
     android:gravity="center" 
     android:paddingTop="50dp" 
     android:text="Hello" /> 

    <TextView 
     android:id="@+id/ProductDetailsTitle8" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffffff" 
     android:gravity="center" 
     android:paddingTop="50dp" 
     android:text="Hello, something" /> 

    </LinearLayout> 
</LinearLayout> 

enter image description here

0

Я знаю, что это старый пост, но я боролся с этим, а также. То, что я нахожу, является наиболее эффективным, это раздуть представление, а затем установить новые параметры линейного макета. Это приведет к тому, что два строчных и однострочных текста будут правильно выравниваться по вертикали.

LayoutInflater inflater = (LayoutInflater) this.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    TextView textView = (TextView) inflater.inflate(R.layout.workout_summary_textview, null); 
    inflater = null; 

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height); 
    params.gravity = Gravity.CENTER; 

    textView.setLayoutParams(params); 
Смежные вопросы