如何在安卓中设计类似的布局

4
我想设计一个类似的布局。例如:当用户触摸“喜欢”按钮时,显示一个布局在其上方以显示贴纸。
请看这张图片以了解我的意思:

enter image description here

你能给我指导吗?

3个回答

3

Rahul Tiwari有很好的解决方案,你也可以使用相对布局

在相对布局中,你可以使用水平线性布局

最后将动画设置为隐藏和显示水平线性布局

水平线性布局应该是视图的前景

阅读它 以了解动画基础知识


3

当用户点击了“喜欢”按钮时,您需要在您的布局上方保留一个隐藏的线性布局,并使其可见。

这个隐藏的布局将包含您的贴纸:

例如:

布局将类似于以下内容:

<LinearLayout
    android:id="@+id/buttonContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:visibility="gone"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/option1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_weight="1"
        android:scaleType="fitCenter"
        android:src="@drawable/image1" />

    <ImageView
        android:id="@+id/option2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_weight="1"
        android:scaleType="fitCenter"
        android:src="@drawable/image2" />

    <ImageView
        android:id="@+id/option3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_weight="1"
        android:scaleType="fitCenter"
        android:src="@drawable/image3" />
</LinearLayout>

将其放置在点赞按钮上方的布局中,并根据您的需要进行自定义。

当您点击点赞按钮时,您需要使其可见,如下所示:

findViewById(R.id.buttonContainer).setVisibility(View.VISIBLE);

并且一旦选择了图像,再次隐藏视图,就像这样:

 findViewById(R.id.buttonContainer).setVisibility(View.GONE);

希望这可以帮到您。

谢谢,你能给我发送源代码或示例代码吗?以便我查看和学习。谢谢 <3 - ydstsh
我用这段代码,但是当点击按钮时显示FC错误。我的代码: bt = (Button) view.findViewById(R.id.button123); bt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { l1 = view.findViewById(R.id.buttonContainer).setVisibility(View.VISIBLE); } }); - ydstsh
哦,我做到了。谢谢你的帮助 <3 - ydstsh

1
我可以按照以下方式为您提供指导。
按照以下方式创建您的布局。
当您单击按钮时,使其可见。
并将其移动到如下所示的“like”按钮上方。 lytMenu.setX(x, likeButton.getY() - lytMenu.getHeight());
如果您这样做,当您设置它可见时,您的菜单布局将重叠其他内容。否则,它将调整您的主布局大小。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.sampleforstack.MainActivity" >

    <!--This is your main layout. Add your content here -->
    <LinearLayout 
        android:id="@+id/lytMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/accent_material_dark">

    </LinearLayout>
    <!--This is your menu layout. Add smile buttons here -->
    <LinerLayout
        android:id="@+id/lytMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone">
    </LinerLayout>

</RelativeLayout>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接