开发者

Aligning center relative to others

开发者 https://www.devze.com 2023-03-23 13:56 出处:网络
So it\'s possible to align the top, bottom, left, and right of one view with another so that their edges are flush with each other. However, I\'ve been wondering if it\'s possible to align the centers

So it's possible to align the top, bottom, left, and right of one view with another so that their edges are flush with each other. However, I've been wondering if it's possible to align the centers of two views of different sizes. My situation occurs when I have an ImageView side by side with a TextView, like this: [ImageView] [TextView]. The ImageView is bit taller than the TextView and so what I do is add padding/margins to the bottom of TextView to get it align and look like the ImageView and TextView horizontal centers are aligned. 开发者_开发知识库Problem is, when this view is displayed on larger tablet screens, the padding and margins don't work out right and the TextView doesn't look aligned with the ImageView. I'm sure there is an easy fix to allow this to always work out, so could someone provide me with some insights? Thanks!


This is how I did for a listview row:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#FFFFFF"
  android:padding="5dp"
  android:gravity="center_vertical">
  <TextView android:id="@+id/questionItemTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="20sp"
    android:textColor="#000000"
    android:gravity="center_vertical"/>
  <ImageView android:id="@+id/questionViewed"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/eye"
    android:layout_marginLeft="5dp" />
  <ImageView android:id="@+id/questionAnswered"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/check"
    android:layout_marginLeft="5dp" />
</LinearLayout>


Use weightSum rather than padding in dips or pxs, that will make your layout look fine regardless of the size of the user's device.

or you could use gravity as well.

Or you can create a second xml file and insert that one into your res/xlarge file, the phone will pick which xml to read.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号