[英]Alignment issue for textview in android
我正在嘗試使文本“您的令牌用完,請重新連接”,位於圖標和標題“ facebook”和“ twitter”正下方,但它們之間有很大的距離。 我嘗試了所有可能的方法,但不確定在哪里丟失。 下面是我的代碼n屏幕截圖。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dip"
android:src="@drawable/facebook" />
<TextView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="10dip"
android:text="Facebook"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#444444"
android:textSize="20sp" />
<ImageView
android:id="@+id/facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:paddingRight="15dip"
android:src="@drawable/ok" />
</LinearLayout>
<TextView android:id="@+id/tokentextfacebook"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/facebook"
android:textSize="14sp"
android:paddingLeft="10dip"
android:background="#ffffff"
android:text="Your token is run out. Please reconnect"
android:textColor="#444444"
android:gravity="left"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="horizontal">
<ImageView
android:id="@+id/facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dip"
android:src="@drawable/twitter" />
<TextView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="10dip"
android:text="Twitter"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#4a82ae"
android:textSize="20sp" />
<ImageView
android:id="@+id/twitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:paddingRight="15dip"
android:src="@drawable/ok" />
</LinearLayout>
<TextView android:id="@+id/tokentexttwitter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/facebook"
android:textSize="14sp"
android:paddingLeft="10dip"
android:background="#ffffff"
android:text="Your token is run out. Please reconnect"
android:textColor="#444444"
android:gravity="left"
/>
</LinearLayout>
</LinearLayout>
使用RelativeLayout可以更輕松地實現此設計,但是無論如何,您都可以在TextView上使用負邊距正確定位它。
android:layoutMarginTop="-10dp"
嘗試
android:paddingBottom =“ 30dip”
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dip"
android:src="@drawable/facebook" />
<TextView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="10dip"
android:text="Facebook"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#444444"
android:textSize="20sp" />
<ImageView
android:id="@+id/facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:paddingRight="15dip"
android:src="@drawable/ok" />
</LinearLayout>
<TextView android:id="@+id/tokentextfacebook"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/facebook"
android:textSize="14sp"
android:paddingLeft="10dip"
android:background="#ffffff"
android:text="Your token is run out. Please reconnect"
android:paddingBottom="30dip"
android:textColor="#444444"
android:gravity="left"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="horizontal">
<ImageView
android:id="@+id/facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dip"
android:src="@drawable/twitter" />
<TextView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="10dip"
android:text="Twitter"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#4a82ae"
android:textSize="20sp" />
<ImageView
android:id="@+id/twitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:paddingRight="15dip"
android:src="@drawable/ok" />
</LinearLayout>
<TextView android:id="@+id/tokentexttwitter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/facebook"
android:textSize="14sp"
android:paddingLeft="10dip"
android:background="#ffffff"
android:text="Your token is run out. Please reconnect"
android:textColor="#444444"
android:paddingBottom="30dip"
android:gravity="left"
/>
</LinearLayout>
</LinearLayout>
Probelm iw的最低身高標准在錯誤的位置,請使用剛剛修改的此布局。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dip"
android:src="@drawable/facebook" />
<TextView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_vertical"
android:paddingLeft="10dip"
android:text="Facebook"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#444444"
android:textSize="20sp" />
<ImageView
android:id="@+id/facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:paddingRight="15dip"
android:src="@drawable/ok" />
</LinearLayout>
<TextView
android:id="@+id/tokentextfacebook"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/facebook"
android:layout_gravity="top"
android:background="#ffffff"
android:gravity="left"
android:paddingLeft="10dip"
android:text="Your token is run out. Please reconnect"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="horizontal" >
<ImageView
android:id="@+id/facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dip"
android:src="@drawable/twitter" />
<TextView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_vertical"
android:paddingLeft="10dip"
android:text="Twitter"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#4a82ae"
android:textSize="20sp" />
<ImageView
android:id="@+id/twitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:paddingRight="15dip"
android:src="@drawable/ok" />
</LinearLayout>
<TextView
android:id="@+id/tokentexttwitter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/facebook"
android:background="#ffffff"
android:gravity="left"
android:paddingLeft="10dip"
android:text="Your token is run out. Please reconnect"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.