2012-04-05 103 views
0

有很多的麻烦图标蜷缩成我想要的位置,我看着3点不同的堆栈溢出的问题,并试图将图片放置在一个RelativeLayout的。 LinearLayout和TableRow。所有与各种XML选项。从来没有设法让图标向右移动,并将其本身置于分配空间的顶部和底部之间。在下面的图片中,红色是现在的位置,蓝色是我想要的位置。这里有一个照片(它现在的样子,这是不正确的),代码(imageView1是我要对齐的):简单的布局问题 - 对齐菜单按钮,最右边,中心

enter image description here

,代码:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:id="@+id/loginScrollView"> 
    <TableLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:orientation="vertical" 
     android:padding="5dp"> 

     <ImageView android:id="@+id/logoImageView" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:src="@drawable/logo" android:contentDescription="@string/app_name" /> 

     <TextView android:id="@+id/demoTextView" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:text="@string/logDetails" android:gravity="center_horizontal|center" /> 

     <EditText android:id="@+id/emailEditText" 
      android:layout_width="match_parent" android:layout_height="wrap_content" 
      android:hint="@string/loginHint" android:imeOptions="actionNext" 
      android:inputType="textEmailAddress" android:padding="20dp" /> 

     <EditText android:id="@+id/passEditText" 
      android:layout_width="match_parent" android:layout_height="wrap_content" 
      android:hint="@string/password" android:imeOptions="actionDone" 
      android:inputType="textPassword" android:padding="20dp" /> 

     <TableRow android:id="@+id/rememberTableRow" 
      android:layout_width="wrap_content" android:layout_height="wrap_content"> 
      <TextView android:id="@+id/rememberTextView" 
       android:layout_width="wrap_content" android:layout_height="wrap_content" 
       android:text="@string/rememberDetails" android:layout_gravity="center" /> 

      <CheckBox android:id="@+id/rememberCheckBox" 
       android:layout_width="wrap_content" android:layout_height="wrap_content" 
       android:padding="20dp" /> 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="showPopup" 
       android:src="@drawable/abs__ic_menu_moreoverflow_holo_dark" android:layout_weight="1" android:layout_gravity="center|right"/> 

     </TableRow> 

     <TableRow android:id="@+id/buttonTableRow" 
      android:layout_width="match_parent" android:layout_height="wrap_content"> 

      <Button android:id="@+id/registerButton" android:layout_width="0dip" 
       android:layout_height="wrap_content" android:layout_gravity="bottom" 
       android:layout_weight="1" android:text="@string/register" /> 

      <Button android:id="@+id/loginButton" android:layout_width="0dip" 
       android:layout_height="wrap_content" android:layout_gravity="bottom" 
       android:layout_weight="1" android:text="@string/login" /> 
     </TableRow> 

    </TableLayout> 
</ScrollView> 

这里有所以我已经看过和问题尝试作为解决方案使用方法: Aligning ImageView to right of the layout android Aligning with center in android with hierarchical Layouts Android ImageButton not displaying on right side of the screen

+1

在哪里,你需要帮助的ImageView的?它在图片中吗? – 2012-04-05 21:05:48

+0

是的它是一个刚刚复选框的权利:它看起来像一个标准的菜单图标(3个竖框)。 – Davek804 2012-04-05 21:08:55

+0

唉唉我刚回到家,有一种答案是哈 – 2012-04-06 02:06:58

回答

1

有AR据我所知,有多种选择。我给你两个:

第一种选择是设置一个scaletype含溢出图标ImageView的。你让它占用所有剩余的可用空间和scaletype设置为fitEnd。这将使图标始终位于右侧。

<ImageView android:id="@+id/imageView1" 
    android:layout_width="0dp" android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical" android:scaleType="fitEnd" 
    android:layout_weight="1" android:onClick="showPopup" 
    android:src="@drawable/abs__ic_menu_moreoverflow_normal_holo_dark" /> 

您可以通过设置的1重量的复选框,这将使其成为“推”与溢流图标一路权的ImageView(多亏了的TableRow类似的行为,以达到相同的效果一个LinearLayout)。然后你可以简单地让ImageView包装它的内容。不过,在这种情况下,您可能需要仔细检查是否对可点击区域没有奇怪的副作用。

<TableRow android:id="@+id/rememberTableRow" 
    android:layout_width="wrap_content" android:layout_height="wrap_content"> 

    <TextView android:id="@+id/rememberTextView" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_gravity="center" android:text="@string/rememberDetails" /> 

    <CheckBox android:id="@+id/rememberCheckBox" 
     android:layout_width="0dp" android:layout_height="wrap_content" 
     android:layout_weight="1" android:padding="20dp" /> 

    <ImageView android:id="@+id/imageView1" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" android:onClick="showPopup" 
     android:src="@drawable/abs__ic_menu_moreoverflow_normal_holo_dark" /> 

</TableRow> 
+0

android:scaleTyle =“fitEnd”完美运作。我实际上删除了我尝试用来将菜单图像放入其中的TableRow。我之前没有看过scaleType,非常感谢! – Davek804 2012-04-05 22:12:25