how to align image view and textview to left using relative layout and textview aligned center below image view with height and width wrap content.
Below is my code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/CardViewManageAccount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/four"
android:layout_marginLeft="@dimen/Eight"
android:layout_marginRight="@dimen/Eight"
android:layout_marginTop="@dimen/four">
<RelativeLayout
android:id="@+id/banklayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/Eight"
android:layout_marginTop="@dimen/Eight">
<LinearLayout
android:id="@+id/ImageLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/TwentyFive"
android:orientation="vertical">
<ImageView
android:id="@+id/bankLogoImg"
android:layout_width="@dimen/FiftyFour"
android:layout_height="@dimen/FiftyFour"
android:layout_alignTop="@+id/bankAccountNumber"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp" />
<TextView
android:id="@+id/accountTypeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/bankLogoImg"
android:layout_marginStart="30dp"
android:layout_marginTop="@dimen/Eight"
android:background="@drawable/rectanle_boarder"
android:ellipsize="marquee"
android:text=""
android:textAlignment="center"
android:textSize="@dimen/Fifteen" />
</LinearLayout>
<LinearLayout
android:id="@+id/bankLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/bankAccountNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="@dimen/TwentyFive"
android:layout_marginTop="@dimen/Eight"
android:layout_toEndOf="@+id/ImageLayout"
android:ellipsize="marquee"
android:text="xxxxxxxx2862"
android:textSize="@dimen/TwentyFive" />
<TextView
android:id="@+id/bankNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/bankAccountNumber"
android:layout_marginLeft="@dimen/TwentyFive"
android:layout_marginTop="@dimen/Two"
android:layout_toEndOf="@+id/bankLogoImg"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Bank of Baroda"
android:textSize="@dimen/Eighteen" />
<TextView
android:id="@+id/bankCodeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/bankNameText"
android:layout_below="@+id/bankNameText"
android:layout_marginLeft="@dimen/TwentyFive"
android:ellipsize="marquee"
android:singleLine="true"
android:text="BARJKJHS"
android:textSize="@dimen/Eighteen" />
<TextView
android:id="@+id/upiLengthText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/bankCodeText"
android:layout_marginBottom="@dimen/Two"
android:layout_marginLeft="@dimen/TwentyFive"
android:layout_marginTop="@dimen/Ten"
android:layout_toEndOf="@+id/bankLogoImg"
android:ellipsize="marquee"
android:singleLine="true"
android:text="UPI PIN LENGTH :"
android:textSize="@dimen/Eighteen" />
</LinearLayout>
<ImageView
android:id="@+id/defaultBankTick"
android:layout_width="@dimen/TwentyFour"
android:layout_height="@dimen/TwentyFour"
android:layout_alignParentRight="true"
android:layout_marginBottom="@dimen/FiftyFive"
android:layout_marginRight="@dimen/Thirty"
android:layout_marginTop="@dimen/FiftyFive"
app:srcCompat="@drawable/black_untick" />
</RelativeLayout>
</android.support.v7.widget.CardView>
下面是我的布局xml的完整代码: 父布局是相对布局,我在代码中给出了两个布局,即图像布局和银行布局,我需要图像布局frist然后银行布局和内部图像布局我需要放置imageview和textview(图像视图中心)
如何实现这个??
答案 0 :(得分:1)
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/banklayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="vertical">
<ImageView
android:id="@+id/bankLogoImg"
android:layout_width="54dp"
android:layout_height="54dp"
android:layout_centerVertical="true"
android:src="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/accountTypeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ellipsize="marquee"
android:text="test"
android:textAlignment="center" />
</LinearLayout>
</RelativeLayout>
答案 1 :(得分:1)
首先使用android:layout_alignLeft="@+id/accountTypeText"
将图片视图左侧与文本视图对齐,然后使用android:gravity="center"
<RelativeLayout
android:id="@+id/banklayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/Eight"
android:layout_marginTop="@dimen/Eight">
<ImageView
android:id="@+id/bankLogoImg"
android:layout_width="@dimen/FiftyFour"
android:layout_height="@dimen/FiftyFour"
android:layout_marginStart="30dp"
android:layout_alignLeft="@+id/accountTypeText"
android:layout_alignTop="@+id/bankAccountNumber"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/accountTypeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:layout_below="@+id/bankLogoImg"
android:text=""
android:gravity="center"
android:background="@drawable/rectanle_boarder"
android:textSize="@dimen/Fifteen" />
</RelativeLayout>
答案 2 :(得分:0)
<RelativeLayout
android:layout_width="@dimen/FiftyFour"
android:layout_height="@dimen/FiftyFour"
android:layout_marginStart="30dp"
android:layout_alignTop="@+id/bankAccountNumber"
android:layout_centerVertical="true">
<TextView
android:layout_alignParentBottom="true"
android:id="@+id/accountTypeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center"
android:background="@drawable/rectanle_boarder"
android:textSize="@dimen/Fifteen"
android:text="sdf" />
<ImageView
android:id="@+id/bankLogoImg"
android:layout_above="@+id/accountTypeText"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>