gpt4 book ai didi

java - 如何将 Image View 和 TexView 左右对齐?

转载 作者:行者123 更新时间:2023-11-29 04:20:26 25 4
gpt4 key购买 nike

下面是我的布局文件。但我无法将 Textview (@id/role) 和 Imageview(@id/flag) 左右对齐。文本似乎在 ImageView 之上。

下面是我的布局文件

<?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="horizontal"
>
<ImageView
android:id="@+id/flag"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/bas" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:orientation="vertical">


<TextView
android:id="@+id/name"
android:text="Xyz Nepal"
android:padding="5dp"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/red"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/role"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginTop="15dp"
android:layout_toLeftOf="@id/flag"
android:padding="5dp"
android:text=" Nepali physicist specializing in cosmology. Having worked in the Central Department of Physics for 34 years"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#027e76"
android:textStyle="bold" />

<TextView
android:layout_marginTop="15dp"
android:id="@+id/desc"
android:layout_margin="5dp"
android:padding="5dp"
android:text="Binil Aryal is the Professor and newly appointed Head of the Department at Central Department of Physics, Tribhuvan University, Kathmandu, Nepal.He was Born in 1969-09-28 in Saptari District of Eastern Nepal.
He is one of the actively working astrophysicist of Nepal. He has been working in the field of Galaxy orientation and Evolution. He has served as a judge of International Astronomy Olympiad. He is the country representative of BCVSPIN school.

He was awarded by 'Mahendra Bidhya Bhushan ka' by the late king Birendra Shah for securing highest score in the M.Sc. Examination. He received 'Third World Academy Award (TWAS)' for his Ph.D. work."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />

<TextView
android:padding="5dp"
android:layout_margin="5dp"
android:id="@+id/email"
android:text="xyz@gmail.com"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#0d38f7"/>

</LinearLayout>


</RelativeLayout>

是这样的

enter image description here

这就是我想要的

enter image description here

提前致谢。我确实使用了 Linearlayou 和 Relativelayout 来定位项目,但我做得很糟糕,而且我想无论屏幕大小如何都拉伸(stretch) TextView ,但不要与图像重叠并始终保持在图像的左侧。

最佳答案

试试这段代码看看是不是你想要的。

<?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="horizontal">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:text="@string/xyz"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />

<ImageView
android:id="@+id/flag"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_margin="5dp"
android:src="@drawable/launcher"
android:layout_alignParentEnd="true" />

<TextView
android:id="@+id/role"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginTop="15dp"
android:padding="5dp"
android:layout_below="@id/name"
android:layout_toLeftOf="@id/flag"
android:text="@string/role
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#027e76"
android:textStyle="bold" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="@id/role"
android:padding="10dp">


<TextView
android:id="@+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginTop="15dp"
android:padding="5dp"
android:text="@string/desc"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />

<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:text="xyz@gmail.com"
android:textColor="#0d38f7" />

</LinearLayout>

关于java - 如何将 Image View 和 TexView 左右对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49589455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com