我尝试将image(imageBottom)
置于滚动view(scrollView)
下方,但它与滚动视图的左下角重叠。
我还在layout_below
中尝试了属性imageview
,但这个技巧很有效。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.rohitkumar.androidtutorial.MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageIcon"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/TextString"
android:textSize="32sp" />
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView1"
android:layout_marginBottom="30dp"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/longText"
android:textSize="20sp" />
</ScrollView>
<ImageView
android:id="@+id/imageIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:contentDescription=""
app:srcCompat="@drawable/course1" />
<ImageView
android:id="@+id/imageBottom"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:contentDescription="@string/course_image"
android:src="@drawable/image_1" />
</RelativeLayout>
答案 0 :(得分:0)
创建相对布局并将textview和图像图标放在其中:
<RelativeLayout
android:id="@+id/rl1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageIcon"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/TextString"
android:textSize="32sp" />
<ImageView
android:id="@+id/imageIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:contentDescription=""
app:srcCompat="@drawable/course1" />
</RelativeLayout
在您的滚动视图中添加android:layout_above="@+id/imageBottom"
和android:layout_below="@+id/rl1"
答案 1 :(得分:0)
您只想滚动文本视图而不需要任何滚动视图,您可以像这样滚动textview:
只需设置
即可 android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"
布局&x文件中TextView的属性。
然后使用:
yourTextView.setMovementMethod(new ScrollingMovementMethod());
你的代码中的。
并将android:layout_above="@+id/imageBottom"
添加到textView,并android:layout_below="@+id/textView1"
删除滚动视图布局
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_above="@+id/imageBottom"
android:gravity="center"
android:text="@string/TextString"
android:textSize="32sp" />
答案 2 :(得分:0)
试试这个。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageIcon"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="hi"
android:textSize="32sp" />
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/imageBottom"
android:layout_below="@+id/textView1"
android:layout_marginBottom="30dp"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20sp" />
</ScrollView>
<ImageView
android:id="@+id/imageBottom"
android:layout_alignParentBottom="true"
android:layout_width="100dp"
android:layout_height="100dp"
/>
<ImageView
android:id="@+id/imageIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:contentDescription=""
/>
</RelativeLayout>
答案 3 :(得分:0)
@Rohit Kumar你只需在滚动视图android:layout_above="@+id/imageBottom"
和android:layout_below="@+id/textView1"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.rohitkumar.androidtutorial.MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageIcon"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="Title"
android:textSize="32sp" />
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/imageBottom"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView1"
android:layout_marginBottom="30dp"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="this is a simple paragraph that is meant to be nice and easy to type which is why there will be mommas no periods or any capital letters so i guess this means that it cannot really be considered a paragraph but just a series of run on sentences this should help you get faster at typing as im trying not to use too many difficult words in it although i think that i might start making it hard by including some more difficult letters I'm typing pretty quickly so forgive me for any mistakes i think that i will not just tell you a story about the time i went to the zoo and found"
android:textSize="20sp" />
</ScrollView>
<ImageView
android:id="@+id/imageIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:contentDescription="test"
app:srcCompat="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/imageBottom"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@mipmap/ic_launcher" />
</RelativeLayout>