在布局中部分滑动视图

时间:2013-02-28 20:41:20

标签: android

我在布局中有两个视图。在视图1中单击按钮时,第二个视图必须可见,并且必须拖入视图1(虽然不完全)。如果还没有清楚,我很抱歉。为了简化我正在附上一些图片。enter image description here

当我点击按钮2;视图1变得可见(白色视图)并且应该占据屏幕的大约85%,并且在屏幕上只能看到蓝色球的一部分。到目前为止我做了什么,我已经给予视图1的重量为0.2和将视图1视为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>

1 个答案:

答案 0 :(得分:0)

您应该可以使用其中一个 Sliding Menu 模式实现进行此类互动。 Jeremy Feinstein已经实现了最常用的一个,你可以在github上抓住它:https://github.com/jfeinstein10/SlidingMenu

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

您甚至可以找到示例eclipse项目here。它将帮助您轻松掌握代码。