【发布时间】:2018-01-29 06:05:23
【问题描述】:
我不想使用过多的线性布局来设置重心。有更好的解决方案吗?谢谢!
这是线性布局的解决方案,但有人告诉我我需要使用相对布局来实现,因为使用太多线性布局会导致渲染缓慢,但我没有成功使用相对布局。
<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="com.example.dan.movietracker.fragments.HomeFragment">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/action_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:layout_marginRight="@dimen/margin_right_genres"
android:text="@string/action"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/advendure_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/adventure"
android:layout_marginRight="@dimen/margin_right_genres"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/animation_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/animation"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="@dimen/margin_top_genres"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/comedy_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:layout_marginRight="@dimen/margin_right_genres"
android:text="@string/comedy"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/crime_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/crime"
android:layout_marginRight="@dimen/margin_right_genres"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/documntary_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/documentary"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="@dimen/margin_top_genres"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/drama_Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:layout_marginRight="@dimen/margin_right_genres"
android:text="@string/drama"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/family_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/crime"
android:layout_marginRight="@dimen/margin_right_genres"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/fantasy_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/documentary"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="@dimen/margin_top_genres"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/history_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:layout_marginRight="@dimen/margin_right_genres"
android:text="@string/history"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/horror_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/horror"
android:layout_marginRight="@dimen/margin_right_genres"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/music_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/music"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="@dimen/margin_top_genres"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/mystery_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:layout_marginRight="@dimen/margin_right_genres"
android:text="@string/mystery"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/romance_Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/romance"
android:layout_marginRight="@dimen/margin_right_genres"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/scienceFiction_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/science_fiction"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="@dimen/margin_top_genres"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/thriller_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:layout_marginRight="@dimen/margin_right_genres"
android:text="@string/thriller"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/war_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/war"
android:layout_marginRight="@dimen/margin_right_genres"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
<TextView
android:id="@+id/western_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/genresTextBackground"
android:padding="@dimen/padding_genres"
android:text="@string/western"
android:textColor="@color/genresTextColor"
android:textSize="@dimen/text_size"
android:textStyle="bold"
/>
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
您能否至少包含一些代码,以便尽最大努力生成此活动布局?
-
至少放一些你的xml代码。
-
我添加了线性布局的代码。谢谢。
标签: java android xml layout android-relativelayout