2013-02-28 324 views
1

我在布局中有两个视图。在视图1中单击按钮时,第二个视图必须可见并且视图1必须被拖入(尽管不完全)。对不起如果没有清楚。为了简化事情我附上一些图像。 enter image description here在布局中部分滑动视图

当我点击按钮2;视图1变得可见(白色视图),并且应该占据屏幕的大约85%,并且只有一部分蓝色球应该可以在屏幕上看到。到目前为止我所做的是我已经给予视图1为0.2的重量并且将视图2视为0.80,并将视图1视为消失。在按钮单击(按钮2)时,我已将视图1视为可见。此工作正常,但我希望只有部分蓝色球可在屏幕上显示,但蓝色球出现sqeezed而不是只有一部分球是可见的。可以有人告诉我,我在这做错了什么?或者是否有其他方法来做到这一点?预先感谢如果有人可以帮助我在这!

我的XML文件如下:

<LinearLayout 
     android:id="@+id/rootlayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:weightSum="1" 
    > 

    <LinearLayout 
       android:id="@+id/bbb" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="0.9" 

       > 
      <include 
       android:id="@+id/background_template_top" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       layout="@layout/menuitems" 
      /> 


    </LinearLayout> 


<RelativeLayout 
    android:id="@+id/parentlayout" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:layout_weight="0.1" 
    > 

    <include 
     android:id="@+id/background_template_top" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     layout="@layout/template_top" 
     android:layout_alignParentTop="true" 
     > 

    </include> 

    <RelativeLayout 
     android:id="@+id/parent_middle_botom" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/background_template_top" 
     > 


<RelativeLayout 
    android:id="@+id/middle" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/black_strip_med" 
    android:layout_below="@+id/background_template_top" 
    > 

    <LinearLayout 
     android:id="@+id/text_data" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_toRightOf="@+id/imageView1" 
     android:layout_marginLeft="30dp" 
     android:orientation="vertical" 
     > 

     <TextView 
     android:id="@+id/welcome" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Welcome," 
     android:textColor="#FFFFFFFF" 
     android:textSize="20sp" 
      android:singleLine="true" 
     > 

    </TextView> 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Joyson" 
     android:layout_below="@+id/welcome" 
      android:textColor="#FFFFFFFF" 
     android:textSize="24sp" 
     android:singleLine="true" 
     > 
    </TextView> 

     </LinearLayout> 



    </RelativeLayout> 

    <include 
     android:id="@+id/background_template_bottom" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     layout="@layout/template_bottom" 
     android:layout_below="@+id/middle" 
     > 
     </include> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/round_sm_device" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="10dp" 

     /> 

      <RelativeLayout 
     android:id="@+id/details" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView1" 
     android:layout_marginLeft="28dp" 
     > 
     <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:src="@drawable/btn_on_small" /> 

     <TextView 
     android:id="@+id/currentbatch" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Current Batch :" 
     android:layout_toRightOf="@+id/imageView2" 
     android:textSize="20dp" 
     android:textStyle="bold" 
      android:singleLine="true" 
     /> 

     <ImageView 
     android:id="@+id/dummy" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/btn_on_small" 
     android:layout_below="@+id/imageView2" 
     android:visibility="invisible" 
     /> 
     <TextView 
      android:id="@+id/count" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/currentbatch" 
      android:text="0" 
      android:layout_toRightOf="@+id/dummy" 
      android:layout_marginLeft="4dp" 
      android:layout_marginTop="4dp" 
      > 
      </TextView> 

    <TextView 
      android:id="@+id/Transaction" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Transactions |" 
      android:layout_toRightOf="@+id/count" 
      android:layout_marginLeft="4dp" 
      android:layout_below="@+id/currentbatch" 
      android:layout_marginTop="4dp" 
      android:textSize="15sp" 
       android:singleLine="true" 
      > 
      </TextView> 

     <TextView 
      android:id="@+id/value" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="$ 0.00" 
      android:layout_toRightOf="@+id/Transaction" 
      android:layout_marginLeft="4dp" 
      android:layout_below="@+id/currentbatch" 
      android:layout_marginTop="4dp" 
      android:textSize="15sp" 
       android:singleLine="true" 
      > 
      </TextView> 


     </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:background="@drawable/welcome_bg_small" 
     > 
     </RelativeLayout> 

    </RelativeLayout> 
    </RelativeLayout> 


</LinearLayout> 
</RelativeLayout> 

这是我所包含的文件:

<?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" > 

    <ScrollView 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:layout_centerHorizontal="true" 
     android:scrollbars="none" 
     android:layout_marginTop="14dp"> 

<RelativeLayout 
    android:id="@+id/parentlayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

    <LinearLayout 
     android:id="@+id/creditcard_functions" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/med_black_strip" 
     android:orientation="vertical" 
     > 
     <TextView 
      android:id="@+id/reporting" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Reporting" 
      android:textColor="#FFFFFFFF" 
      android:paddingLeft="8dp" 
      android:textSize="20dp" 
      android:textStyle="bold" 
      > 
     </TextView> 


     <TextView 
      android:id="@+id/functions" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Functions" 
      android:textColor="#FFFFFFFF" 
      android:paddingLeft="8dp" 
      android:textSize="20dp" 
      android:textStyle="bold" 
      > 
     </TextView> 
    </LinearLayout> 

    <RelativeLayout 
     android:id="@+id/sale" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/creditcard_functions" 
     android:background="@drawable/med_black_strip" 

     > 
     <ImageView 
      android:id="@+id/sale_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/balance_inquiry_icon" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      > 
     </ImageView> 

     <TextView 
      android:id="@+id/saletext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Sale" 
      android:layout_centerInParent="true" 
      android:textColor="#FFFFFFFF" 
      android:textSize="25sp" 
      android:textStyle="bold" 
      > 

      </TextView> 


     </RelativeLayout> 


    <RelativeLayout 
     android:id="@+id/authorizeonly" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/sale" 
     android:background="@drawable/med_black_strip" 

     > 
     <ImageView 
      android:id="@+id/authorize_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/balance_inquiry_icon" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      > 
     </ImageView> 

     <TextView 
      android:id="@+id/authorize_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
       android:text="Sale" 
      android:layout_centerInParent="true" 
      android:textColor="#FFFFFFFF" 
      android:textSize="25sp" 
      android:textStyle="bold" 
      > 
     </TextView> 
     </RelativeLayout> 


    <RelativeLayout 
     android:id="@+id/Ticketonly" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/authorizeonly" 
     android:background="@drawable/med_black_strip" 

     > 
     <ImageView 
      android:id="@+id/ticketonly_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/balance_inquiry_icon" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      > 
     </ImageView> 

     <TextView 
      android:id="@+id/tickettext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Sale" 
      android:layout_centerInParent="true" 
      android:textColor="#FFFFFFFF" 
      android:textSize="25sp" 
      android:textStyle="bold" 
      > 
     </TextView> 
     </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/giftcardfunctions" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/Ticketonly" 
     android:background="@drawable/med_black_strip" 

     > 
     <TextView 
      android:id="@+id/giftcardfunctionstext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text=" Functions" 
      android:textColor="#FFFFFFFF" 
      android:paddingLeft="8dp" 
      android:textSize="20dp" 
      android:textStyle="bold" 
      android:layout_centerVertical="true" 
      > 
      </TextView> 

     </RelativeLayout> 


     <RelativeLayout 
     android:id="@+id/Redeem" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/giftcardfunctions" 
     android:background="@drawable/med_black_strip" 

     > 
     <ImageView 
      android:id="@+id/redeeem_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/balance_inquiry_icon" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      > 
     </ImageView> 

     <TextView 
      android:id="@+id/redeemtext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Sale" 
      android:layout_centerInParent="true" 
      android:textColor="#FFFFFFFF" 
      android:textSize="25sp" 
      android:textStyle="bold" 
      > 
     </TextView> 
     </RelativeLayout> 



     <RelativeLayout 
     android:id="@+id/Activate" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/Redeem" 
     android:background="@drawable/med_black_strip" 
     > 
     <ImageView 
      android:id="@+id/activate_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/balance_inquiry_icon" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      > 
     </ImageView> 

     <TextView 
      android:id="@+id/activatetext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Sale" 
      android:layout_centerInParent="true" 
      android:textColor="#FFFFFFFF" 
      android:textSize="25sp" 
      android:textStyle="bold" 
      > 
     </TextView> 
     </RelativeLayout> 


      <RelativeLayout 
     android:id="@+id/Deactivate" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/Activate" 
     android:background="@drawable/med_black_strip" 
     > 
     <ImageView 
      android:id="@+id/deactivate_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/balance_inquiry_icon" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      > 
     </ImageView> 

     <TextView 
      android:id="@+id/deactivatetext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Sale" 
      android:layout_centerInParent="true" 
      android:textColor="#FFFFFFFF" 
      android:textSize="25sp" 
      android:textStyle="bold" 
      > 
     </TextView> 
     </RelativeLayout> 


      <RelativeLayout 
     android:id="@+id/Addvalue" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/Deactivate" 
     android:background="@drawable/med_black_strip" 
     > 
     <ImageView 
      android:id="@+id/addvalue_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/add_value" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      > 
     </ImageView> 

     <TextView 
      android:id="@+id/addvaluetext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Add Value" 
      android:layout_centerInParent="true" 
      android:textColor="#FFFFFFFF" 
      android:textSize="25sp" 
      android:textStyle="bold" 
      > 
     </TextView> 
     </RelativeLayout> 



     <RelativeLayout 
     android:id="@+id/BalanceInquiry" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/Addvalue" 
     android:background="@drawable/med_black_strip" 
     > 
     <ImageView 
      android:id="@+id/balanceinquiry_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/balance_inquiry_icon" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      > 
     </ImageView> 

     <TextView 
      android:id="@+id/balanceinquirytext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Balance Inquiry" 
      android:layout_centerInParent="true" 
      android:textColor="#FFFFFFFF" 
      android:textSize="25sp" 
      android:textStyle="bold" 
      > 
     </TextView> 
     </RelativeLayout> 

     <RelativeLayout 
     android:id="@+id/Transfer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/BalanceInquiry" 
     android:background="@drawable/med_black_strip" 
     > 
     <ImageView 
      android:id="@+id/transfer_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/transfer_icon" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      > 
     </ImageView> 

     <TextView 
      android:id="@+id/transfertext" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Transfer" 
      android:layout_centerInParent="true" 
      android:textColor="#FFFFFFFF" 
      android:textSize="25sp" 
      android:textStyle="bold" 
      > 
     </TextView> 
     </RelativeLayout> 

    </RelativeLayout> 
    </ScrollView> 

</RelativeLayout> 
+0

这种交互让我想起** Sliding菜单模式**(http://www.androiduipatterns.com/2012/06/emerging-ui-pattern-side-navigation.html)如果是这种情况,您可以整合像这样一个很酷的图书馆https://github.com/jfeinstein10/SlidingMenu。 – 2013-02-28 21:11:26

+0

prixing应用程序(在提到的第一个链接中的子链接)具有完全相同的UI,我期待创建。 – Joyson 2013-03-01 05:56:35

+0

我在下面添加了我的答案。如果您认为它适合您的需要,请将其标记为已接受。 – 2013-03-01 10:58:40

回答

0

你应该能够得到使用一个这样的交互Sliding Menu模式实现在那里。其中最常用的一个已经由Jeremy Feinstein实现,您可以在github上抓取它:https://github.com/jfeinstein10/SlidingMenu

它已经很简单了,您可以在xml或代码中使用它。查看github上的readme页面以获取有关设置的更多信息。

你甚至可以找到一个例子eclipse项目here。它会帮助你用代码弄脏你的手。

+0

@ mr_achano,谢谢你! – Joyson 2013-03-02 14:53:29