【问题标题】:How can a title of an article by the side in android如何在android中将文章标题放在旁边
【发布时间】:2018-10-11 10:04:44
【问题描述】:

我是 Android 的初学者,我的老师给了我创建此布局的任务,我知道如何创建副标题位于顶部但不在侧面的布局Image for the layout 这是代码:

<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="com.example.lielhanohov.scrollingtext.MainActivity">

    <TextView
        android:id="@+id/article_heading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:padding="@dimen/padding_regular"
        android:text="@string/article_title"
        android:textAppearance="@android:style/TextAppearance.Large"
        android:textColor="@android:color/white"
        android:textStyle="bold" />

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/article_heading">

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

            <TextView
                android:id="@+id/article_subheading"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:padding="@dimen/padding_regular"
                android:text="@string/article_subheading"
                android:textAppearance="@android:style/TextAppearance" />

            <TextView
                android:id="@+id/article"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoLink="web"
                android:lineSpacingExtra="@dimen/line_spacing"
                android:text="@string/Article_text" />

        </LinearLayout>
    </ScrollView>
</RelativeLayout>

【问题讨论】:

标签: java android xml kotlin


【解决方案1】:

您可以使用 ConstraintLayout 而不是 LinearLayout,并将文章的左侧限制在副标题的右侧。

我还注意到您正在使用 RelativeLayout 作为根布局。建议使用 ConstraintLayout 而不是 RelativeLayout,因为它有助于创建更扁平、性能更高的布局。但是,在这种情况下,将 LinearLayout 作为根布局可能是更好的选择。

有关 ConstraintLayout 的更多信息,请参阅:https://developer.android.com/training/constraint-layout/https://developer.android.com/reference/android/support/constraint/ConstraintLayout 它非常强大,尤其是在创建更复杂的布局时。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-03
    • 2014-05-28
    • 1970-01-01
    相关资源
    最近更新 更多