0

かなりシンプルなレイアウトで8つのテキストビューを追加しようとしています。1行に2つのテキストビューと4つのそのような行が必要です。私の課題は、このレイアウトで2番目、4番目、6番目、8番目のテキストビューを並べることです。1番目、3番目、5番目、および7番目のテキストビューのテキストの長さは異なります。

各行の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>
4

2 に答える 2

0

これが古い投稿であることは知っていますが、これにも苦労しました。私が見つけた最も効果的なのは、ビューを膨らませてから、新しい線形レイアウト パラメータを設定することです。これにより、2 行と 1 行のテキスト ビューが垂直方向の中央に適切に配置されます。

    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);
于 2015-04-23T15:07:59.057 に答える
0

多分これが役立つかもしれません。それぞれの 、 、および を操作してbackground color、思い通りにすることができます。お役に立てれば。top paddingTextView

<?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>

ここに画像の説明を入力

于 2012-07-05T05:23:28.697 に答える