2012-01-29 7 views
13

を下にスクロールして、私は次のようなレイアウトを持っている:RelativeLayout -

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    android:id="@+navigate/RLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#ABABAB" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    > 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textStyle="bold" 
     android:id="@+id/myid" 
     android:layout_centerHorizontal="true" 
     android:src="@drawable/myid" 
     android:layout_marginTop="15dp" />. 
    <RelativeLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="10dp" 
     android:orientation="vertical" 
     android:id="@+id/firstRectangle" 
     android:background="@drawable/bg" 
     android:layout_below="@+id/myid" > 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textStyle="bold|italic" 
     android:textColor="#000000" 
     android:id="@+id/hotelinfos" 
     android:layout_marginTop="10dp" 
     android:layout_marginLeft="10dp" 
     android:layout_below="@+id/myid" 
     android:layout_alignLeft="@+id/myid"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textStyle="bold" 
     android:textColor="#000000" 
     android:id="@+id/hotelname" 
     android:layout_below="@+id/hotelinfos" 
     android:layout_alignLeft="@+id/hotelinfos" 
     android:layout_marginTop="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/hoteladdress" 
     android:layout_below="@+id/hotelname" 
     android:layout_alignLeft="@+id/hotelname" 
     android:layout_marginTop="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:id="@+id/hotelphone" 
     android:layout_below="@+id/hoteladdress" 
     android:layout_alignLeft="@+id/hoteladdress" 
     android:layout_marginTop="10dp" 
     android:textColor="#12C" 
     android:textStyle="bold|italic" 
     android:onClick="onClick" 
     android:clickable="true" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#12C" 
     android:onClick="onClick" 
     android:clickable="true" 
     android:textStyle="bold|italic" 
     android:id="@+id/hotelemail" 
     android:layout_below="@+id/hotelphone" 
     android:layout_alignLeft="@+id/hotelphone" 
     android:layout_marginTop="10dp" 
     android:paddingBottom="10dp" /> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/picture" 
     android:layout_below="@+id/myid" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="10dp"  
     android:layout_marginTop="10dp"/> 
    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="10dp" 
     android:orientation="vertical" 
     android:id="@+id/SecondRectangle" 
     android:background="@drawable/bg" 
     android:layout_below="@+id/firstRectangle" > 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:textStyle="bold|italic" 
     android:id="@+id/bookinginfos" 
     android:layout_below="@+id/firstRectangle" 
     android:layout_alignLeft="@+id/firstRectangle" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/pnr" 
     android:layout_below="@+id/bookinginfos" 
     android:layout_alignLeft="@+id/bookinginfos" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/segmentCode" 
     android:layout_below="@+id/pnr" 
     android:layout_alignLeft="@+id/pnr" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/checkin" 
     android:layout_below="@+id/segmentCode" 
     android:layout_alignLeft="@+id/segmentCode" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/checkout" 
     android:layout_below="@+id/checkin" 
     android:layout_alignLeft="@+id/checkin" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/nights"  
     android:layout_below="@+id/checkout" 
     android:layout_alignLeft="@+id/checkout" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/roomType" 
     android:layout_below="@+id/nights" 
     android:layout_alignLeft="@+id/nights" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/boardBasis" 
     android:layout_below="@+id/roomType" 
     android:layout_alignLeft="@+id/roomType" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/paxNames" 
     android:layout_below="@+id/boardBasis" 
     android:layout_alignLeft="@+id/boardBasis" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" 
     android:paddingBottom="10dp" /> 
    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="10dp" 
     android:orientation="vertical" 
     android:id="@+id/thirdRectangle" 
     android:background="@drawable/bg" 
     android:layout_below="@+id/SecondRectangle" > 
      <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:textStyle="bold|italic" 
     android:id="@+id/forHotel" 
     android:layout_below="@+id/SecondRectangle" 
     android:layout_alignLeft="@+id/SecondRectangle" 
     android:layout_marginLeft="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/supplierCode" 
     android:layout_below="@+id/forHotel" 
     android:layout_alignLeft="@+id/forHotel" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" 
     android:paddingBottom="10dp"/> 
     </ScrollView> 

    </RelativeLayout> 
</RelativeLayout> 

relativelayoutの最後の部分が表示されていないので、私は、このレイアウトでスクロールしたいと思います! しかし、私はそれを行う方法を知らない。 私はscrollviewを追加しようとしましたが、私はエラーを受け取りました:scrollviewは1つの直接の子供をホストすることができます! 私のためのヒントはありますか?

ご協力いただきありがとうございます。

+0

はあなたが私たちに追加scrollviewを使用してXMLファイルを表示することができ、なぜなら私が見る限り、スクロールビューを使用して動作するはずですuちょうど見落としを作った – joni

答えて

41

ScrollViewのように、単一の子ビューを期待して、あなたのレイアウトで、あなたが2 TextViewを持っていることになります。あなたがLinearLayoutまたはRelativeLayoutのようなのViewGroupにごTextViewをラップする必要がScrollView仕事をするために 。

編集コード:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> 
<RelativeLayout 
    android:id="@+navigate/RLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ABABAB" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    > 
// ... THE REST OF YOUR CODE 
</RelativeLayout> 
</ScrollView> 
+0

こんにちはslukian! 実際、私はScrollViewが私にとって正しいソリューションであるかどうかはわかりません。 ユーザーが画面にタッチしたときにrelativeLayoutに移動したい... どうすればよいか分かりません><" –

+0

@JohnSmith私は自分の答えを編集したので、' ScrollView'に最後の 'RelativeLayout 'thirdRectangleは、私はあなたがやろうとしているのか理解していない:。(どのように正確「で動く」)に移動しrelativeLayout(relativeLayout?)ユーザーが画面に触れたとき、あなたが説明してもらえ – Luksprog

+0

まあ、私の最後のrelativeLayoutです。? (レイアウトは、携帯電話の画面よりも大きいので!) 隠して、私は下にスクロールすることができない... Androidは自動的にそれを行うことはありません? –

3

あなたは、スクロールを開始する権利の上にこのコードを取る:

<ScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    > 

その後、あなたはそれを停止したいときに終わります。

3

scrollviewが唯一の子を持つことができるので、子供がどのlayoutすることができます。 LinearLayoutまたはRelativeLayoutになります。だからこのようなものに違いないはずです。 <ScrollView><RelativeLayout></RelativeLayout></ScrollView>

あなたのコードは、この

<RelativeLayout 
android:id="@+navigate/RLayout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#ABABAB" 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 

<ScrollView> 
android:id="@+navigate/Scrollview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<RelativeLayout 
android:id="@+navigate/RLayout02" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 

> 
<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textStyle="bold" 
    android:id="@+id/hcorpo" 
    android:layout_centerHorizontal="true" 
    android:src="@drawable/hcorpo" 
    android:layout_marginTop="15dp" />. 
<RelativeLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:layout_margin="10dp" 
    android:orientation="vertical" 
    android:id="@+id/firstRectangle" 
    android:background="@drawable/bg" 
    android:layout_below="@+id/hcorpo" > 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textStyle="bold|italic" 
    android:textColor="#000000" 
    android:id="@+id/hotelinfos" 
    android:layout_marginTop="10dp" 
    android:layout_marginLeft="10dp" 
    android:layout_below="@+id/hcorpo" 
    android:layout_alignLeft="@+id/hcorpo"/> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textStyle="bold" 
    android:textColor="#000000" 
    android:id="@+id/hotelname" 
    android:layout_below="@+id/hotelinfos" 
    android:layout_alignLeft="@+id/hotelinfos" 
    android:layout_marginTop="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/hoteladdress" 
    android:layout_below="@+id/hotelname" 
    android:layout_alignLeft="@+id/hotelname" 
    android:layout_marginTop="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:id="@+id/hotelphone" 
    android:layout_below="@+id/hoteladdress" 
    android:layout_alignLeft="@+id/hoteladdress" 
    android:layout_marginTop="10dp" 
    android:textColor="#12C" 
    android:textStyle="bold|italic" 
    android:onClick="onClick" 
    android:clickable="true" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#12C" 
    android:onClick="onClick" 
    android:clickable="true" 
    android:textStyle="bold|italic" 
    android:id="@+id/hotelemail" 
    android:layout_below="@+id/hotelphone" 
    android:layout_alignLeft="@+id/hotelphone" 
    android:layout_marginTop="10dp" 
    android:paddingBottom="10dp" /> 
<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/picture" 
    android:layout_below="@+id/hcorpo" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="10dp"  
    android:layout_marginTop="10dp"/> 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:layout_margin="10dp" 
    android:orientation="vertical" 
    android:id="@+id/SecondRectangle" 
    android:background="@drawable/bg" 
    android:layout_below="@+id/firstRectangle" > 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:textStyle="bold|italic" 
    android:id="@+id/bookinginfos" 
    android:layout_below="@+id/firstRectangle" 
    android:layout_alignLeft="@+id/firstRectangle" 
    android:layout_marginLeft="10dp" 
    android:layout_marginTop="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/pnr" 
    android:layout_below="@+id/bookinginfos" 
    android:layout_alignLeft="@+id/bookinginfos" 
    android:layout_marginTop="10dp" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/segmentCode" 
    android:layout_below="@+id/pnr" 
    android:layout_alignLeft="@+id/pnr" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/checkin" 
    android:layout_below="@+id/segmentCode" 
    android:layout_alignLeft="@+id/segmentCode" 
    android:layout_marginTop="10dp" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/checkout" 
    android:layout_below="@+id/checkin" 
    android:layout_alignLeft="@+id/checkin" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/nights"  
    android:layout_below="@+id/checkout" 
    android:layout_alignLeft="@+id/checkout" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/roomType" 
    android:layout_below="@+id/nights" 
    android:layout_alignLeft="@+id/nights" 
    android:layout_marginTop="10dp" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/boardBasis" 
    android:layout_below="@+id/roomType" 
    android:layout_alignLeft="@+id/roomType" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/paxNames" 
    android:layout_below="@+id/boardBasis" 
    android:layout_alignLeft="@+id/boardBasis" 
    android:layout_marginTop="10dp" 
    android:layout_marginRight="10dp" 
    android:paddingBottom="10dp" /> 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:layout_margin="10dp" 
    android:orientation="vertical" 
    android:id="@+id/thirdRectangle" 
    android:background="@drawable/bg" 
    android:layout_below="@+id/SecondRectangle" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:textStyle="bold|italic" 
    android:id="@+id/forHotel" 
    android:layout_below="@+id/SecondRectangle" 
    android:layout_alignLeft="@+id/SecondRectangle" 
    android:layout_marginLeft="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/supplierCode" 
    android:layout_below="@+id/forHotel" 
    android:layout_alignLeft="@+id/forHotel" 
    android:layout_marginTop="10dp" 
    android:layout_marginRight="10dp" 
    android:paddingBottom="10dp"/> 


</RelativeLayout> 
</RelativeLayout> 

</ScrollView> 

</RelativeLayout> 
3

あなたの最後のRelativeLayout

<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="10dp" 
     android:orientation="vertical" 
     android:id="@+id/thirdRectangle" 
     android:background="@drawable/bg" 
     android:layout_below="@+id/SecondRectangle" > 
      <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:textStyle="bold|italic" 
     android:id="@+id/forHotel" 
     android:layout_below="@+id/SecondRectangle" 
     android:layout_alignLeft="@+id/SecondRectangle" 
     android:layout_marginLeft="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/supplierCode" 
     android:layout_below="@+id/forHotel" 
     android:layout_alignLeft="@+id/forHotel" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" 
     android:paddingBottom="10dp"/> 
     </ScrollView> 

    </RelativeLayout> 

代わりに次のようになります。

<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"> 
<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="10dp" 
     android:orientation="vertical" 
     android:id="@+id/thirdRectangle" 
     android:background="@drawable/bg" 
     android:layout_below="@+id/SecondRectangle" > 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:textStyle="bold|italic" 
     android:id="@+id/forHotel" 
     android:layout_below="@+id/SecondRectangle" 
     android:layout_alignLeft="@+id/SecondRectangle" 
     android:layout_marginLeft="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/supplierCode" 
     android:layout_below="@+id/forHotel" 
     android:layout_alignLeft="@+id/forHotel" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" 
     android:paddingBottom="10dp"/> 

    </RelativeLayout> 
</ScrollView>