如何在android视图中为所有内容正确定义大小?
我定义了一个包含如何在android视图中为所有内容正确定义大小?,android,android-linearlayout,android-relativelayout,Android,Android Linearlayout,Android Relativelayout,我定义了一个包含文本视图、图像视图和按钮的布局 在xml文件中,我尝试使用LinearLayout来包含这些视图。这是正确的(我可以看到我的文本视图然后是我的图像视图然后是我的按钮),但有时文本视图太长,我看不到我的图像视图和按钮 我尝试了RelativeLayout,但没有产生预期的结果 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com
文本视图
、图像视图
和按钮
的布局
在xml文件中,我尝试使用LinearLayout来包含这些视图。这是正确的(我可以看到我的文本视图
然后是我的图像视图
然后是我的按钮
),但有时文本视图
太长,我看不到我的图像视图
和按钮
我尝试了RelativeLayout
,但没有产生预期的结果
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash" >
<TextView
android:id="@+id/storybox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="all"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Texte"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="20px" />
<ImageView
android:id="@+id/ivImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Images"
android:onClick="onButtonDownUpActivityClick" />
</LinearLayout>
只需将
线性布局
包装在滚动视图中
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/splash" >
...
....
....
...
</LinearLayout>
</ScrollView>
...
....
....
...
您可能正在寻找ScrollView
,它是一个布局元素,用于容纳屏幕上过大的项目。ScrollView
应该只有一个子项(您的RelativeLayout
),然后该子项包含更复杂的布局
查看Android开发者指南了解更多信息: