【发布时间】:2016-11-24 20:05:08
【问题描述】:
问题是 whithin 3 imageviews don't display toast,而且我试图在其 onlick 中记录任何文本,并且来自匿名也没有任何建议? Screenshot
我的 XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/bg_login"
android:orientation="vertical"
android:paddingBottom="19dp"
android:paddingLeft="10dp"
android:paddingRight="9dp"
tools:context="com.example.mahmoud.blink.LoginFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="217dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="51dp"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:src="@mipmap/logo_small" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@mipmap/overlay_white"
android:clickable="false"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<ImageView
android:id="@+id/iv_tm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:clickable="true"
app:srcCompat="@mipmap/t" />
<ImageView
android:id="@+id/iv_fbm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="31dp"
android:layout_marginRight="31dp"
android:layout_toLeftOf="@+id/iv_tm"
android:layout_toStartOf="@+id/iv_tm"
android:background="@mipmap/f"
android:clickable="true" />
<ImageView
android:id="@+id/iv_googlem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="31dp"
android:layout_marginStart="31dp"
android:layout_toEndOf="@+id/iv_tm"
android:layout_toRightOf="@+id/iv_tm"
android:clickable="true"
app:srcCompat="@mipmap/g" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/txtEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10.5dp"
android:layout_marginRight="12dp"
android:drawableLeft="@mipmap/mail2"
android:drawablePadding="10dp"
android:hint="Email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/txtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10.5dp"
android:layout_marginRight="12dp"
android:drawableLeft="@mipmap/password"
android:drawablePadding="10dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword" />
</LinearLayout>
<com.wang.avi.AVLoadingIndicatorView
android:id="@+id/avi"
style="@style/AVLoadingIndicatorView.Large"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical|center_horizontal"
app:indicatorColor="@color/colorPrimary"
app:indicatorName="BallClipRotatePulseIndicator" />
</FrameLayout>
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="15dp"
android:background="@mipmap/normal_btn"
android:text="Sign In"
android:textColor="#8b572a" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="@+id/btn_forget_pass"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/sencondry_btn"
android:text="Forgot Password"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="6dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="@+id/btn_signup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/sencondry_btn"
android:text="Sign up"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Java 代码
在 LoginFragment.java 中
//decleration within the fragment class
ImageView iv_g;
ImageView iv_fb;
ImageView iv_t;
来自 onCreateView 方法
View view = inflater.inflate(R.layout.fragment_login, container, false);
iv_fb = (ImageView) view.findViewById(R.id.iv_fbm);
iv_t = (ImageView) view.findViewById(R.id.iv_tm);
iv_g = (ImageView) view.findViewById(R.id.iv_googlem);
iv_fb.setOnClickListener(this);
iv_g.setOnClickListener(this);
iv_t.setOnClickListener(this);
来自 onClick 方法
if (v.getId() == R.id.iv_googlem) {
Toast.makeText(context, "google", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context, MyService.class);
intent.putExtra("type", "google");
context.startService(intent);
} else if (v.getId() == R.id.iv_fbm) {
Toast.makeText(context, "facebook", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context, MyService.class);
intent.putExtra("type", "facebook");
context.startService(intent);
} else if (v.getId() == R.id.iv_tm) {
Toast.makeText(context, "twitter", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context, MyService.class);
intent.putExtra("type", "twitter");
context.startService(intent);
}
3 个按钮可以正常工作,但是单击时 3 个 ImageViews 不会触发
【问题讨论】:
-
您能在
if块内记录任何内容吗,例如Log.v("Test");? -
不要使用 Toast 进行调试。改用 Log.d("TAG", "MESSAGE")
标签: android xml android-layout android-studio android-fragments