在线性布局内的ScrollView内并排对齐TextView

时间:2013-11-22 15:40:17

标签: android xml android-layout

我有一个带有scrollview的线性布局,我想保留它的当前格式 - 但只是并排放置textView2a和textView3a而不会破坏我当前的布局格式。

我已将最近的尝试包括在内 - 但它们似乎并不正确。

提前致谢!

-JavaNoob

当前工作XML

<LinearLayout 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:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:textStyle="bold" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:id="@+id/groupScrollView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <com.google.android.youtube.player.YouTubePlayerView
                android:id="@+id/youtubeplayerview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView1a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Throw &apos;Em Up"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by User1"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="100,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <com.google.android.youtube.player.YouTubeThumbnailView
                android:id="@+id/youtubethumbnailview1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Bulls On Parade"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by Rage Against the Machine"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="100,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>

            <com.google.android.youtube.player.YouTubeThumbnailView
                android:id="@+id/youtubethumbnailview2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=" Anderson Cooper"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by idconex"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="678,000,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />


            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>
        </LinearLayout>


    </ScrollView>

</LinearLayout>

通过侧面对齐添加尝试:

<LinearLayout 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:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:autoLink="web"
        android:textStyle="bold" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:id="@+id/groupScrollView">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <com.google.android.youtube.player.YouTubePlayerView
                android:id="@+id/youtubeplayerview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/textView1a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Throw &apos;Em Up"
                android:textAppearance="?android:attr/textAppearanceMedium" />
  <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
            <TextView
                android:id="@+id/textView2a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by DJ Generic"
                android:layout_toLeftOf="@+id/textView3a"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="100,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />
    </RelativeLayout>
            <com.google.android.youtube.player.YouTubeThumbnailView
                android:id="@+id/youtubethumbnailview1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Bulls On Parade"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by Rage Against the Machine"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="100,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>

            <com.google.android.youtube.player.YouTubeThumbnailView
                android:id="@+id/youtubethumbnailview2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp" />

            <TextView
                android:id="@+id/textView1b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="CNN Anderson Cooper"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView2b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="by idconex"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="678,000,000 views"
                android:textAppearance="?android:attr/textAppearanceSmall" />          

            <View
                android:layout_width="1dp"
                android:layout_height="5dp" >
            </View>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

2 个答案:

答案 0 :(得分:3)

尝试替换它:

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textView2a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/textView3a"
        android:text="by DJ Generic"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView3a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="100,000 views"
        android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>

由此:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView2a"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:layout_toLeftOf="@+id/textView3a"
        android:text="by DJ Generic"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView3a"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:text="100,000 views"
        android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>

如果这是你想做的事,请告诉我。

答案 1 :(得分:0)

试试这个..

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
     android:orientation="horizontal">
            <TextView
                android:id="@+id/textView2a"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="by DJ Generic"
                android:gravity="center"
                android:layout_gravity="center"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView3a"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="100,000 views"
                android:gravity="center"
                android:layout_gravity="center"
                android:textAppearance="?android:attr/textAppearanceSmall" />
    </LinearLayout>