[英]How to place a TextView right on the upper edge of a LinearLayout in Android?
I want to set a TextView
right on the upper edge of a LinearLayout
in Android. 我想在Android的
LinearLayout
的上边缘设置一个TextView
。
I'm trying to achieve something like this 我正在努力实现这样的目标
But I'm getting this: 但是我得到这个:
What I have done so far: 到目前为止,我所做的是:
content_main.xml content_main.xml
<?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/tableLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="tries.auro.tryapp.MainActivity"
tools:showIn="@layout/activity_main"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:scrollbars="vertical"
android:background="@drawable/bg"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="33dp"
android:id="@+id/linearLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="BLAH BLAH!!"
android:id="@+id/textView"
android:layout_marginLeft="33dp"
android:layout_marginStart="33dp"
android:layout_alignTop="@+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</LinearLayout>
</RelativeLayout>
And I made a background, called bg.xml for my LinearLayout
我为
LinearLayout
创建了一个名为bg.xml的背景
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<solid android:color="#000000"/>
</shape>
</item>
<item
android:left="2dp"
android:right="2dp"
android:bottom="2dp"
android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
</shape>
</item>
</layer-list>
I am quite new to Android & I find this quite challenging. 我对Android还是很陌生,我觉得这很有挑战性。 So I was wondering if anyone knew how I could achieve this
所以我想知道是否有人知道我如何实现这一目标
Thank you for your time!! 感谢您的时间!!
Please check this one 请检查这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:background="@drawable/bg" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="40dp"
android:layout_marginTop="15dp"
android:background="@drawable/bg"
android:text=";dslf;ldfsgk;" />
I would try to do something like this (Use the code of floating action button but change the floating action button with a TextView): 我会尝试做这样的事情(使用浮动动作按钮的代码,但使用TextView更改浮动动作按钮):
<android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout>
<LinearLayout
android:id="@+id/viewA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.15">
</LinearLayout>
<LinearLayout
android:id="@+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.85" >
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_horizontal_margin"
app:layout_anchor="@id/viewA"
app:layout_anchorGravity="left|bottom"/>
</android.support.design.widget.CoordinatorLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.